Skip to content

Commit 1765c16

Browse files
committed
fix the unit test
1 parent e7eccd3 commit 1765c16

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

evm-tests/src/subtensor.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,4 @@ export async function setTargetRegistrationsPerInterval(
386386
call: internal_tx.decodedCall,
387387
});
388388
await waitForTransactionWithRetry(api, tx, alice);
389-
}
390-
391-
export async function disableCommitRevealWeights(api: TypedApi<typeof devnet>, netuid: number) {
392-
const alice = getAliceSigner()
393-
const enabled = await api.query.SubtensorModule.CommitRevealWeightsEnabled.getValue(netuid)
394-
395-
if (enabled === true) {
396-
const internalCall = api.tx.AdminUtils.sudo_set_commit_reveal_weights_enabled({ netuid, enabled: false })
397-
const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall })
398-
await waitForTransactionWithRetry(api, tx, alice)
399-
}
400-
401-
const newEnabled = await api.query.SubtensorModule.CommitRevealWeightsEnabled.getValue(netuid)
402-
// could create multiple subnetworks during retry, just return the first created one
403-
assert.equal(newEnabled, false)
404389
}

evm-tests/test/neuron.precompile.reveal-weights.test.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import { generateRandomEthersWallet } from "../src/utils"
1111
import { convertH160ToPublicKey } from "../src/address-utils"
1212
import { blake2AsU8a } from "@polkadot/util-crypto"
1313
import {
14-
forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, addNewSubnetwork, setCommitRevealWeightsEnabled, setWeightsSetRateLimit, burnedRegister,
14+
forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, addNewSubnetwork, setWeightsSetRateLimit, burnedRegister,
1515
setTempo, setCommitRevealWeightsInterval,
1616
startCall,
17-
disableCommitRevealWeights
1817
} from "../src/subtensor"
1918

2019
// hardcode some values for reveal hash
@@ -53,6 +52,7 @@ describe("Test neuron precompile reveal weights", () => {
5352
const coldkey = getRandomSubstrateKeypair();
5453

5554
let api: TypedApi<typeof devnet>
55+
let commitEpoch: number;
5656

5757
// sudo account alice as signer
5858
let alice: PolkadotSigner;
@@ -66,14 +66,11 @@ describe("Test neuron precompile reveal weights", () => {
6666
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(coldkey.publicKey))
6767
await forceSetBalanceToEthAddress(api, wallet.address)
6868
let netuid = await addNewSubnetwork(api, hotkey, coldkey)
69-
await disableCommitRevealWeights(api, netuid)
69+
// await disableCommitRevealWeights(api, netuid)
7070
await startCall(api, netuid, coldkey)
7171

7272
console.log("test the case on subnet ", netuid)
7373

74-
// enable commit reveal feature
75-
await setCommitRevealWeightsEnabled(api, netuid, true)
76-
// set it as 0, we can set the weight anytime
7774
await setWeightsSetRateLimit(api, netuid, BigInt(0))
7875

7976
const ss58Address = convertH160ToSS58(wallet.address)
@@ -92,8 +89,15 @@ describe("Test neuron precompile reveal weights", () => {
9289
const subnetId = totalNetworks - 1
9390
const commitHash = getCommitHash(subnetId, wallet.address)
9491
const contract = new ethers.Contract(INEURON_ADDRESS, INeuronABI, wallet);
95-
const tx = await contract.commitWeights(subnetId, commitHash)
96-
await tx.wait()
92+
try {
93+
const tx = await contract.commitWeights(subnetId, commitHash)
94+
await tx.wait()
95+
} catch (e) {
96+
console.log("commitWeights failed", e)
97+
}
98+
99+
const commitBlock = await api.query.System.Number.getValue()
100+
commitEpoch = Math.trunc(commitBlock / (100 + 1))
97101

98102
const ss58Address = convertH160ToSS58(wallet.address)
99103

@@ -110,9 +114,19 @@ describe("Test neuron precompile reveal weights", () => {
110114
const netuid = totalNetworks - 1
111115
const contract = new ethers.Contract(INEURON_ADDRESS, INeuronABI, wallet);
112116
// set tempo or epoch large, then enough time to reveal weight
113-
await setTempo(api, netuid, 60000)
114-
// set interval epoch as 0, we can reveal at the same epoch
115-
await setCommitRevealWeightsInterval(api, netuid, BigInt(0))
117+
await setTempo(api, netuid, 100)
118+
// set interval epoch as 1, it is the minimum value now
119+
await setCommitRevealWeightsInterval(api, netuid, BigInt(1))
120+
121+
while (true) {
122+
const currentBlock = await api.query.System.Number.getValue()
123+
const currentEpoch = Math.trunc(currentBlock / (100 + 1))
124+
// wait for one second for fast blocks
125+
if (currentEpoch > commitEpoch) {
126+
break
127+
}
128+
await new Promise(resolve => setTimeout(resolve, 1000))
129+
}
116130

117131
const tx = await contract.revealWeights(
118132
netuid,
@@ -122,6 +136,7 @@ describe("Test neuron precompile reveal weights", () => {
122136
version_key
123137
);
124138
await tx.wait()
139+
125140
const ss58Address = convertH160ToSS58(wallet.address)
126141

127142
// check the weight commit is removed after reveal successfully

0 commit comments

Comments
 (0)