@@ -11,6 +11,7 @@ import {
1111 forceSetBalanceToEthAddress , forceSetBalanceToSs58Address , addNewSubnetwork , burnedRegister ,
1212 sendProxyCall ,
1313 startCall ,
14+ getStake ,
1415} from "../src/subtensor"
1516import { ETH_LOCAL_URL } from "../src/config" ;
1617import { ISTAKING_ADDRESS , ISTAKING_V2_ADDRESS , IStakingABI , IStakingV2ABI } from "../src/contracts/staking"
@@ -54,7 +55,7 @@ describe("Test neuron precompile add remove stake", () => {
5455 let netuid = ( await api . query . SubtensorModule . TotalNetworks . getValue ( ) ) - 1
5556 // ETH unit
5657 let stakeBalance = raoToEth ( tao ( 20 ) )
57- const stakeBefore = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
58+ const stakeBefore = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
5859 const contract = new ethers . Contract ( ISTAKING_ADDRESS , IStakingABI , wallet1 ) ;
5960 const tx = await contract . addStake ( hotkey . publicKey , netuid , { value : stakeBalance . toString ( ) } )
6061 await tx . wait ( )
@@ -64,15 +65,15 @@ describe("Test neuron precompile add remove stake", () => {
6465 ) ;
6566
6667 assert . ok ( stakeFromContract > stakeBefore )
67- const stakeAfter = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
68+ const stakeAfter = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
6869 assert . ok ( stakeAfter > stakeBefore )
6970 } )
7071
7172 it ( "Can add stake V2" , async ( ) => {
7273 let netuid = ( await api . query . SubtensorModule . TotalNetworks . getValue ( ) ) - 1
7374 // the unit in V2 is RAO, not ETH
7475 let stakeBalance = tao ( 20 )
75- const stakeBefore = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
76+ const stakeBefore = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
7677 const contract = new ethers . Contract ( ISTAKING_V2_ADDRESS , IStakingV2ABI , wallet2 ) ;
7778 const tx = await contract . addStake ( hotkey . publicKey , stakeBalance . toString ( ) , netuid )
7879 await tx . wait ( )
@@ -82,15 +83,15 @@ describe("Test neuron precompile add remove stake", () => {
8283 ) ;
8384
8485 assert . ok ( stakeFromContract > stakeBefore )
85- const stakeAfter = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
86+ const stakeAfter = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
8687 assert . ok ( stakeAfter > stakeBefore )
8788 } )
8889
8990 it ( "Can not add stake if subnet doesn't exist" , async ( ) => {
9091 // wrong netuid
9192 let netuid = 12345 ;
9293 let stakeBalance = raoToEth ( tao ( 20 ) )
93- const stakeBefore = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
94+ const stakeBefore = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
9495 const contract = new ethers . Contract ( ISTAKING_ADDRESS , IStakingABI , wallet1 ) ;
9596 try {
9697 const tx = await contract . addStake ( hotkey . publicKey , netuid , { value : stakeBalance . toString ( ) } )
@@ -104,7 +105,7 @@ describe("Test neuron precompile add remove stake", () => {
104105 await contract . getStake ( hotkey . publicKey , convertH160ToPublicKey ( wallet1 . address ) , netuid )
105106 ) ;
106107 assert . equal ( stakeFromContract , stakeBefore )
107- const stakeAfter = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
108+ const stakeAfter = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet1 . address ) , netuid )
108109 assert . equal ( stakeAfter , stakeBefore )
109110 } ) ;
110111
@@ -113,7 +114,7 @@ describe("Test neuron precompile add remove stake", () => {
113114 let netuid = 12345 ;
114115 // the unit in V2 is RAO, not ETH
115116 let stakeBalance = tao ( 20 )
116- const stakeBefore = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
117+ const stakeBefore = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
117118 const contract = new ethers . Contract ( ISTAKING_V2_ADDRESS , IStakingV2ABI , wallet2 ) ;
118119
119120 try {
@@ -128,7 +129,7 @@ describe("Test neuron precompile add remove stake", () => {
128129 await contract . getStake ( hotkey . publicKey , convertH160ToPublicKey ( wallet2 . address ) , netuid )
129130 ) ;
130131 assert . equal ( stakeFromContract , stakeBefore )
131- const stakeAfter = await api . query . SubtensorModule . Alpha . getValue ( convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
132+ const stakeAfter = await getStake ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) , convertH160ToSS58 ( wallet2 . address ) , netuid )
132133 assert . equal ( stakeAfter , stakeBefore )
133134 } )
134135
@@ -248,7 +249,8 @@ describe("Test neuron precompile add remove stake", () => {
248249
249250 assert . equal ( proxiesAfterAdd [ 0 ] [ 0 ] . delegate , convertPublicKeyToSs58 ( proxy . publicKey ) )
250251
251- let stakeBefore = await api . query . SubtensorModule . Alpha . getValue (
252+ let stakeBefore = await getStake (
253+ api ,
252254 convertPublicKeyToSs58 ( hotkey . publicKey ) ,
253255 ss58Address ,
254256 netuid
@@ -261,7 +263,8 @@ describe("Test neuron precompile add remove stake", () => {
261263 } )
262264 await sendProxyCall ( api , call . decodedCall , ss58Address , proxy )
263265
264- let stakeAfter = await api . query . SubtensorModule . Alpha . getValue (
266+ let stakeAfter = await getStake (
267+ api ,
265268 convertPublicKeyToSs58 ( hotkey . publicKey ) ,
266269 ss58Address ,
267270 netuid
@@ -306,7 +309,8 @@ describe("Test neuron precompile add remove stake", () => {
306309
307310 assert . equal ( proxiesAfterAdd [ 0 ] [ 0 ] . delegate , convertPublicKeyToSs58 ( proxy . publicKey ) )
308311
309- let stakeBefore = await api . query . SubtensorModule . Alpha . getValue (
312+ let stakeBefore = await getStake (
313+ api ,
310314 convertPublicKeyToSs58 ( hotkey . publicKey ) ,
311315 ss58Address ,
312316 netuid
@@ -320,7 +324,8 @@ describe("Test neuron precompile add remove stake", () => {
320324
321325 await sendProxyCall ( api , call . decodedCall , ss58Address , proxy )
322326
323- let stakeAfter = await api . query . SubtensorModule . Alpha . getValue (
327+ let stakeAfter = await getStake (
328+ api ,
324329 convertPublicKeyToSs58 ( hotkey . publicKey ) ,
325330 ss58Address ,
326331 netuid
0 commit comments