@@ -11,9 +11,9 @@ import { generateRandomEthersWallet } from "../src/utils"
1111import { convertH160ToPublicKey } from "../src/address-utils"
1212import { blake2AsU8a } from "@polkadot/util-crypto"
1313import {
14- forceSetBalanceToEthAddress , forceSetBalanceToSs58Address , addNewSubnetwork , setCommitRevealWeightsEnabled , setWeightsSetRateLimit , burnedRegister ,
14+ forceSetBalanceToEthAddress , forceSetBalanceToSs58Address , addNewSubnetwork , setWeightsSetRateLimit , burnedRegister ,
1515 setTempo , setCommitRevealWeightsInterval ,
16- startCall
16+ startCall ,
1717} from "../src/subtensor"
1818
1919// hardcode some values for reveal hash
@@ -52,6 +52,7 @@ describe("Test neuron precompile reveal weights", () => {
5252 const coldkey = getRandomSubstrateKeypair ( ) ;
5353
5454 let api : TypedApi < typeof devnet >
55+ let commitEpoch : number ;
5556
5657 // sudo account alice as signer
5758 let alice : PolkadotSigner ;
@@ -65,13 +66,11 @@ describe("Test neuron precompile reveal weights", () => {
6566 await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( coldkey . publicKey ) )
6667 await forceSetBalanceToEthAddress ( api , wallet . address )
6768 let netuid = await addNewSubnetwork ( api , hotkey , coldkey )
69+ // await disableCommitRevealWeights(api, netuid)
6870 await startCall ( api , netuid , coldkey )
6971
7072 console . log ( "test the case on subnet " , netuid )
7173
72- // enable commit reveal feature
73- await setCommitRevealWeightsEnabled ( api , netuid , true )
74- // set it as 0, we can set the weight anytime
7574 await setWeightsSetRateLimit ( api , netuid , BigInt ( 0 ) )
7675
7776 const ss58Address = convertH160ToSS58 ( wallet . address )
@@ -90,8 +89,15 @@ describe("Test neuron precompile reveal weights", () => {
9089 const subnetId = totalNetworks - 1
9190 const commitHash = getCommitHash ( subnetId , wallet . address )
9291 const contract = new ethers . Contract ( INEURON_ADDRESS , INeuronABI , wallet ) ;
93- const tx = await contract . commitWeights ( subnetId , commitHash )
94- 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 ) )
95101
96102 const ss58Address = convertH160ToSS58 ( wallet . address )
97103
@@ -108,9 +114,19 @@ describe("Test neuron precompile reveal weights", () => {
108114 const netuid = totalNetworks - 1
109115 const contract = new ethers . Contract ( INEURON_ADDRESS , INeuronABI , wallet ) ;
110116 // set tempo or epoch large, then enough time to reveal weight
111- await setTempo ( api , netuid , 60000 )
112- // set interval epoch as 0, we can reveal at the same epoch
113- 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+ }
114130
115131 const tx = await contract . revealWeights (
116132 netuid ,
@@ -120,6 +136,7 @@ describe("Test neuron precompile reveal weights", () => {
120136 version_key
121137 ) ;
122138 await tx . wait ( )
139+
123140 const ss58Address = convertH160ToSS58 ( wallet . address )
124141
125142 // check the weight commit is removed after reveal successfully
0 commit comments