Skip to content

Commit 608533b

Browse files
committed
Merge branch 'devnet-ready' into drand_precompile
2 parents 58311c6 + fe74d6a commit 608533b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+487
-176
lines changed

.github/e2e.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: E2E Tests
2+
3+
on:
4+
workflow_dispatch:

contract-tests/src/subtensor.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,22 @@ export async function setNetworkLastLockCost(api: TypedApi<typeof devnet>, defau
419419

420420
const valueOnChain = await api.query.SubtensorModule.NetworkLastLockCost.getValue()
421421
assert.equal(defaultNetworkLastLockCost, valueOnChain)
422+
}
423+
424+
425+
export async function getStake(api: TypedApi<typeof devnet>, hotkey: string, coldkey: string, netuid: number): Promise<bigint> {
426+
const value = (await api.query.SubtensorModule.AlphaV2.getValue(hotkey, coldkey, netuid));
427+
428+
const mantissa = value.mantissa;
429+
const exponent = value.exponent;
430+
431+
let result: bigint;
432+
433+
if (exponent >= 0) {
434+
result = mantissa * BigInt(10) ** exponent;
435+
} else {
436+
result = mantissa / BigInt(10) ** -exponent;
437+
}
438+
439+
return result;
422440
}

contract-tests/test/alphaPool.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PublicClient } from "viem";
99
import { TypedApi } from "polkadot-api";
1010
import { ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE } from "../src/contracts/alphaPool";
1111
import { convertH160ToPublicKey, convertH160ToSS58, convertPublicKeyToSs58, toViemAddress } from "../src/address-utils";
12-
import { forceSetBalanceToEthAddress, disableWhiteListCheck, addNewSubnetwork, forceSetBalanceToSs58Address, startCall, burnedRegister } from "../src/subtensor";
12+
import { forceSetBalanceToEthAddress, disableWhiteListCheck, addNewSubnetwork, forceSetBalanceToSs58Address, startCall, burnedRegister, getStake } from "../src/subtensor";
1313
import { ethers } from "ethers"
1414
import { tao } from "../src/balance-math";
1515
import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking";
@@ -46,7 +46,7 @@ describe("bridge token contract deployment", () => {
4646
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1
4747
// the unit in V2 is RAO, not ETH
4848
let stakeBalance = tao(20)
49-
const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
49+
const stakeBefore = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
5050
const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet);
5151
const tx = await contract.addStake(hotkey.publicKey, stakeBalance.toString(), netuid)
5252
await tx.wait()
@@ -56,7 +56,7 @@ describe("bridge token contract deployment", () => {
5656
);
5757

5858
assert.ok(stakeFromContract > stakeBefore)
59-
const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
59+
const stakeAfter = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
6060
assert.ok(stakeAfter > stakeBefore)
6161
assert.ok(stakeFromContract > tao(20))
6262
})
@@ -66,7 +66,7 @@ describe("bridge token contract deployment", () => {
6666
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1
6767
const stakingPrecompile = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet);
6868

69-
const stakeBeforeDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
69+
const stakeBeforeDeposit = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
7070

7171
const contractFactory = new ethers.ContractFactory(ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE, wallet)
7272
const contract = await contractFactory.deploy(hotkey.publicKey)
@@ -103,11 +103,11 @@ describe("bridge token contract deployment", () => {
103103
await depositAlphaTx.wait()
104104

105105
// compare wallet stake
106-
const stakeAftereDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
106+
const stakeAftereDeposit = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid)
107107
assert.ok(stakeAftereDeposit < stakeBeforeDeposit)
108108

109109
// check the contract stake
110-
const ContractStake = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid)
110+
const ContractStake = await getStake(api, convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(contractAddress), netuid)
111111
assert.ok(ContractStake > 0)
112112

113113
// check the wallet alpha balance in contract, the actual swapped alpha could be less than alphaAmount in deposit call

contract-tests/test/precompileWrapper.direct-call.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
startCall,
1111
disableWhiteListCheck,
1212
forceSetBalanceToEthAddress,
13+
getStake,
1314

1415
} from "../src/subtensor";
1516
import { ethers } from "ethers";
@@ -147,7 +148,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => {
147148

148149
it("Should add stake via wrapper", async () => {
149150
const stakeAmount = tao(2);
150-
const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(
151+
const stakeBefore = await getStake(
152+
api,
151153
convertPublicKeyToSs58(hotkey.publicKey),
152154
convertH160ToSS58(wrapperAddress),
153155
netuid
@@ -161,7 +163,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => {
161163
);
162164
await addStakeTx.wait();
163165

164-
const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(
166+
const stakeAfter = await getStake(
167+
api,
165168
convertPublicKeyToSs58(hotkey.publicKey),
166169
convertH160ToSS58(wrapperAddress),
167170
netuid
@@ -171,7 +174,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => {
171174

172175
it("Should remove stake via wrapper", async () => {
173176
const removeAmount = tao(1);
174-
const stakeBefore = await api.query.SubtensorModule.Alpha.getValue(
177+
const stakeBefore = await getStake(
178+
api,
175179
convertPublicKeyToSs58(hotkey.publicKey),
176180
convertH160ToSS58(wrapperAddress),
177181
netuid
@@ -184,7 +188,8 @@ describe("PrecompileWrapper - Direct Call Tests", () => {
184188
);
185189
await removeStakeTx.wait();
186190

187-
const stakeAfter = await api.query.SubtensorModule.Alpha.getValue(
191+
const stakeAfter = await getStake(
192+
api,
188193
convertPublicKeyToSs58(hotkey.publicKey),
189194
convertH160ToSS58(wrapperAddress),
190195
netuid

contract-tests/test/staking.precompile.add-remove.test.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, addNewSubnetwork, burnedRegister,
1212
sendProxyCall,
1313
startCall,
14+
getStake,
1415
} from "../src/subtensor"
1516
import { ETH_LOCAL_URL } from "../src/config";
1617
import { 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

contract-tests/test/staking.precompile.burn-alpha.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { convertH160ToPublicKey } from "../src/address-utils"
1010
import {
1111
forceSetBalanceToEthAddress, forceSetBalanceToSs58Address, addNewSubnetwork, burnedRegister,
1212
startCall,
13+
getStake,
1314
} from "../src/subtensor"
1415
import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking"
1516

@@ -72,7 +73,8 @@ describe("Test staking precompile burn alpha", () => {
7273
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1
7374

7475
// Get current stake
75-
const currentStake = await api.query.SubtensorModule.Alpha.getValue(
76+
const currentStake = await getStake(
77+
api,
7678
convertPublicKeyToSs58(hotkey.publicKey),
7779
convertH160ToSS58(wallet1.address),
7880
netuid

contract-tests/test/staking.precompile.full-limit.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
addStake,
1313
forceSetBalanceToEthAddress,
1414
forceSetBalanceToSs58Address,
15+
getStake,
1516
startCall,
1617
} from "../src/subtensor";
1718
import { ethers } from "ethers";
@@ -51,7 +52,8 @@ describe("Test staking precompile add remove limit methods", () => {
5152
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1;
5253
let ss58Address = convertH160ToSS58(wallet1.address);
5354

54-
const alpha = await api.query.SubtensorModule.Alpha.getValue(
55+
const alpha = await getStake(
56+
api,
5557
convertPublicKeyToSs58(hotkey.publicKey),
5658
ss58Address,
5759
netuid,
@@ -72,7 +74,8 @@ describe("Test staking precompile add remove limit methods", () => {
7274
);
7375
await tx.wait();
7476

75-
const alphaAfterAddStake = await api.query.SubtensorModule.Alpha.getValue(
77+
const alphaAfterAddStake = await getStake(
78+
api,
7679
convertPublicKeyToSs58(hotkey.publicKey),
7780
ss58Address,
7881
netuid,
@@ -85,7 +88,8 @@ describe("Test staking precompile add remove limit methods", () => {
8588
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1;
8689
let ss58Address = convertH160ToSS58(wallet1.address);
8790

88-
const alpha = await api.query.SubtensorModule.Alpha.getValue(
91+
const alpha = await getStake(
92+
api,
8993
convertPublicKeyToSs58(hotkey.publicKey),
9094
ss58Address,
9195
netuid,
@@ -104,7 +108,8 @@ describe("Test staking precompile add remove limit methods", () => {
104108
);
105109
await tx.wait();
106110

107-
const alphaAfterRemoveStake = await api.query.SubtensorModule.Alpha.getValue(
111+
const alphaAfterRemoveStake = await getStake(
112+
api,
108113
convertPublicKeyToSs58(hotkey.publicKey),
109114
ss58Address,
110115
netuid,
@@ -120,7 +125,8 @@ describe("Test staking precompile add remove limit methods", () => {
120125
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1;
121126
let ss58Address = convertH160ToSS58(wallet2.address);
122127

123-
const alpha = await api.query.SubtensorModule.Alpha.getValue(
128+
const alpha = await getStake(
129+
api,
124130
convertPublicKeyToSs58(hotkey.publicKey),
125131
ss58Address,
126132
netuid,
@@ -141,7 +147,8 @@ describe("Test staking precompile add remove limit methods", () => {
141147
);
142148
await tx.wait();
143149

144-
const alphaAfterAddStake = await api.query.SubtensorModule.Alpha.getValue(
150+
const alphaAfterAddStake = await getStake(
151+
api,
145152
convertPublicKeyToSs58(hotkey.publicKey),
146153
ss58Address,
147154
netuid,
@@ -154,7 +161,8 @@ describe("Test staking precompile add remove limit methods", () => {
154161
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1;
155162
let ss58Address = convertH160ToSS58(wallet2.address);
156163

157-
const alpha = await api.query.SubtensorModule.Alpha.getValue(
164+
const alpha = await getStake(
165+
api,
158166
convertPublicKeyToSs58(hotkey.publicKey),
159167
ss58Address,
160168
netuid,
@@ -172,7 +180,8 @@ describe("Test staking precompile add remove limit methods", () => {
172180
);
173181
await tx.wait();
174182

175-
const alphaAfterRemoveStake = await api.query.SubtensorModule.Alpha.getValue(
183+
const alphaAfterRemoveStake = await getStake(
184+
api,
176185
convertPublicKeyToSs58(hotkey.publicKey),
177186
ss58Address,
178187
netuid,

0 commit comments

Comments
 (0)