@@ -5,76 +5,53 @@ import { TypedApi } from "polkadot-api";
5
5
import { convertPublicKeyToSs58 } from "../src/address-utils"
6
6
import { tao } from "../src/balance-math"
7
7
import {
8
- forceSetBalanceToSs58Address , addNewSubnetwork , burnedRegister ,
9
- setTxRateLimit , setTempo , setWeightsSetRateLimit , setSubnetOwnerCut , setMaxAllowedUids ,
10
- setMinDelegateTake , becomeDelegate , setActivityCutoff , addStake , setWeight , rootRegister
8
+ forceSetBalanceToSs58Address , addNewSubnetwork , addStake ,
11
9
} from "../src/subtensor"
12
- import { PublicClient } from "viem " ;
13
- import { generateRandomEthersWallet , getPublicClient } from "../src/utils"
14
- import { ISTAKING_ADDRESS , ISTAKING_V2_ADDRESS , IStakingABI , IStakingV2ABI } from "../src/contracts/staking"
15
- import { ETH_LOCAL_URL } from "../src/config " ;
10
+ import { ethers } from "ethers " ;
11
+ import { generateRandomEthersWallet } from "../src/utils"
12
+ import { ISTAKING_V2_ADDRESS , IStakingV2ABI } from "../src/contracts/staking"
13
+ import { log } from "console " ;
16
14
17
- describe ( "Test neuron precompile reveal weights " , ( ) => {
15
+ describe ( "Test staking precompile get methods " , ( ) => {
18
16
const hotkey = getRandomSubstrateKeypair ( ) ;
19
17
const coldkey = getRandomSubstrateKeypair ( ) ;
20
- let publicClient : PublicClient ;
21
-
22
- // const validator = getRandomSubstrateKeypair();
23
- // const miner = getRandomSubstrateKeypair();
24
- // const nominator = getRandomSubstrateKeypair();
18
+ const wallet1 = generateRandomEthersWallet ( ) ;
25
19
26
20
let api : TypedApi < typeof devnet >
27
21
28
22
before ( async ( ) => {
29
- const root_netuid = 0 ;
30
- const root_tempo = 1 ; // neet root epoch to happen before subnet tempo
31
- const subnet_tempo = 1 ;
32
- publicClient = await getPublicClient ( ETH_LOCAL_URL )
33
23
api = await getDevnetApi ( )
34
-
35
- // await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(alice.publicKey))
36
24
await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) )
37
25
await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( coldkey . publicKey ) )
38
- // await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(validator.publicKey))
39
- // await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(miner.publicKey))
40
- // await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(nominator.publicKey))
41
- // await forceSetBalanceToEthAddress(api, wallet1.address)
42
- // await forceSetBalanceToEthAddress(api, wallet2.address)
43
26
let netuid = await addNewSubnetwork ( api , hotkey , coldkey )
44
-
45
- console . log ( "test the case on subnet " , netuid )
46
-
47
- await setTxRateLimit ( api , BigInt ( 0 ) )
48
- await setTempo ( api , root_netuid , root_tempo )
49
- await setTempo ( api , netuid , subnet_tempo )
50
- await setWeightsSetRateLimit ( api , netuid , BigInt ( 0 ) )
51
-
52
- // await burnedRegister(api, netuid, convertPublicKeyToSs58(validator.publicKey), coldkey)
53
- // await burnedRegister(api, netuid, convertPublicKeyToSs58(miner.publicKey), coldkey)
54
- // await burnedRegister(api, netuid, convertPublicKeyToSs58(nominator.publicKey), coldkey)
55
- await setSubnetOwnerCut ( api , 0 )
56
- await setActivityCutoff ( api , netuid , 65535 )
57
- await setMaxAllowedUids ( api , netuid , 65535 )
58
- await setMinDelegateTake ( api , 0 )
59
- // await becomeDelegate(api, convertPublicKeyToSs58(validator.publicKey), coldkey)
60
- // await becomeDelegate(api, convertPublicKeyToSs58(miner.publicKey), coldkey)
27
+ console . log ( "will test in subnet: " , netuid )
61
28
} )
62
29
63
30
it ( "Staker receives rewards" , async ( ) => {
64
31
let netuid = ( await api . query . SubtensorModule . TotalNetworks . getValue ( ) ) - 1
65
32
66
33
await addStake ( api , netuid , convertPublicKeyToSs58 ( hotkey . publicKey ) , tao ( 1 ) , coldkey )
67
34
68
- const value = await publicClient . readContract ( {
69
- address : ISTAKING_ADDRESS ,
70
- abi : IStakingABI ,
71
- functionName : "getStake" ,
72
- args : [ hotkey . publicKey , // Convert to bytes32 format
73
- hotkey . publicKey ,
74
- netuid ]
75
- } )
76
-
77
- console . log ( value )
35
+ const contract = new ethers . Contract (
36
+ ISTAKING_V2_ADDRESS ,
37
+ IStakingV2ABI ,
38
+ wallet1
39
+ ) ;
40
+
41
+ const stake = BigInt (
42
+ await contract . getStake ( hotkey . publicKey , coldkey . publicKey , netuid )
43
+ ) ;
44
+
45
+ // validator returned as bigint now.
46
+ const validators =
47
+ await contract . getAlphaStakedValidators ( hotkey . publicKey , netuid )
48
+
49
+ const alpha = BigInt (
50
+ await contract . getTotalAlphaStaked ( hotkey . publicKey , netuid )
51
+ ) ;
52
+ assert . ok ( stake > 0 )
53
+ assert . equal ( validators . length , 1 )
54
+ assert . ok ( alpha > 0 )
78
55
79
56
} )
80
57
} )
0 commit comments