@@ -11,9 +11,9 @@ import { generateRandomEthersWallet } from "../src/utils"
11
11
import { convertH160ToPublicKey } from "../src/address-utils"
12
12
import { blake2AsU8a } from "@polkadot/util-crypto"
13
13
import {
14
- forceSetBalanceToEthAddress , forceSetBalanceToSs58Address , addNewSubnetwork , setCommitRevealWeightsEnabled , setWeightsSetRateLimit , burnedRegister ,
14
+ forceSetBalanceToEthAddress , forceSetBalanceToSs58Address , addNewSubnetwork , setWeightsSetRateLimit , burnedRegister ,
15
15
setTempo , setCommitRevealWeightsInterval ,
16
- startCall
16
+ startCall ,
17
17
} from "../src/subtensor"
18
18
19
19
// hardcode some values for reveal hash
@@ -52,6 +52,7 @@ describe("Test neuron precompile reveal weights", () => {
52
52
const coldkey = getRandomSubstrateKeypair ( ) ;
53
53
54
54
let api : TypedApi < typeof devnet >
55
+ let commitEpoch : number ;
55
56
56
57
// sudo account alice as signer
57
58
let alice : PolkadotSigner ;
@@ -65,13 +66,11 @@ describe("Test neuron precompile reveal weights", () => {
65
66
await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( coldkey . publicKey ) )
66
67
await forceSetBalanceToEthAddress ( api , wallet . address )
67
68
let netuid = await addNewSubnetwork ( api , hotkey , coldkey )
69
+ // await disableCommitRevealWeights(api, netuid)
68
70
await startCall ( api , netuid , coldkey )
69
71
70
72
console . log ( "test the case on subnet " , netuid )
71
73
72
- // enable commit reveal feature
73
- await setCommitRevealWeightsEnabled ( api , netuid , true )
74
- // set it as 0, we can set the weight anytime
75
74
await setWeightsSetRateLimit ( api , netuid , BigInt ( 0 ) )
76
75
77
76
const ss58Address = convertH160ToSS58 ( wallet . address )
@@ -90,8 +89,15 @@ describe("Test neuron precompile reveal weights", () => {
90
89
const subnetId = totalNetworks - 1
91
90
const commitHash = getCommitHash ( subnetId , wallet . address )
92
91
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 ) )
95
101
96
102
const ss58Address = convertH160ToSS58 ( wallet . address )
97
103
@@ -108,9 +114,19 @@ describe("Test neuron precompile reveal weights", () => {
108
114
const netuid = totalNetworks - 1
109
115
const contract = new ethers . Contract ( INEURON_ADDRESS , INeuronABI , wallet ) ;
110
116
// 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
+ }
114
130
115
131
const tx = await contract . revealWeights (
116
132
netuid ,
@@ -120,6 +136,7 @@ describe("Test neuron precompile reveal weights", () => {
120
136
version_key
121
137
) ;
122
138
await tx . wait ( )
139
+
123
140
const ss58Address = convertH160ToSS58 ( wallet . address )
124
141
125
142
// check the weight commit is removed after reveal successfully
0 commit comments