Skip to content

Commit 5a47059

Browse files
committed
clean up code
1 parent ae7c8ec commit 5a47059

File tree

6 files changed

+13
-33
lines changed

6 files changed

+13
-33
lines changed

contract-tests/run-ci.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if [ "$i" -eq 1000 ]; then
2929
exit 1
3030
fi
3131

32+
# wait for node-subtensor to be stable
3233
sleep 2
3334

3435
if ! nc -z localhost 9944; then
@@ -43,7 +44,7 @@ npm i -g polkadot-api
4344

4445
bash get-metadata.sh
4546

46-
sleep 2
47+
sleep 5
4748

4849
yarn install --frozen-lockfile
4950

@@ -56,8 +57,4 @@ if [ $TEST_EXIT_CODE -ne 0 ]; then
5657
exit $TEST_EXIT_CODE
5758
fi
5859

59-
pkill node-subtensor
60-
61-
sleep 2
62-
6360
exit 0

contract-tests/src/subtensor.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ export async function addNewSubnetwork(api: TypedApi<typeof devnet>, hotkey: Key
1313
const alice = getAliceSigner()
1414
const totalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue()
1515

16-
const defaultNetworkLastLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue()
17-
18-
// const defaultNetworkMinLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue()
19-
2016
const rateLimit = await api.query.SubtensorModule.NetworkRateLimit.getValue()
2117
if (rateLimit !== BigInt(0)) {
2218
const internalCall = api.tx.AdminUtils.sudo_set_network_rate_limit({ rate_limit: BigInt(0) })
@@ -32,8 +28,7 @@ export async function addNewSubnetwork(api: TypedApi<typeof devnet>, hotkey: Key
3228
// could create multiple subnetworks during retry, just return the first created one
3329
assert.ok(newTotalNetworks > totalNetworks)
3430

35-
// reset network last lock cost to 0, to avoid the lock cost calculation error
36-
await setNetworkLastLockCost(api, defaultNetworkLastLockCost)
31+
await resetNetworkLastLockCost(api)
3732
return totalNetworks
3833
}
3934

@@ -408,17 +403,19 @@ export async function sendWasmContractExtrinsic(api: TypedApi<typeof devnet>, co
408403
await waitForTransactionWithRetry(api, tx, signer)
409404
}
410405

411-
export async function setNetworkLastLockCost(api: TypedApi<typeof devnet>, defaultNetworkLastLockCost: bigint) {
406+
// reset network last lock cost to networkMinLockCost, to avoid the lock cost calculation error
407+
export async function resetNetworkLastLockCost(api: TypedApi<typeof devnet>) {
412408
const alice = getAliceSigner()
413409
const key = await api.query.SubtensorModule.NetworkLastLockCost.getKey()
414410
const codec = await getTypedCodecs(devnet);
415-
const value = codec.query.SubtensorModule.NetworkLastLockCost.value.enc(defaultNetworkLastLockCost)
411+
const networkMinLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue()
412+
const value = codec.query.SubtensorModule.NetworkLastLockCost.value.enc(networkMinLockCost)
416413
const internalCall = api.tx.System.set_storage({
417414
items: [[Binary.fromHex(key), Binary.fromBytes(value)]]
418415
})
419416
const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall })
420417
await waitForTransactionWithRetry(api, tx, alice)
421418

422419
const valueOnChain = await api.query.SubtensorModule.NetworkLastLockCost.getValue()
423-
assert.equal(defaultNetworkLastLockCost, valueOnChain)
420+
assert.equal(networkMinLockCost, valueOnChain)
424421
}

contract-tests/test/leasing.precompile.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ethers } from "ethers";
77
import { TypedApi } from "polkadot-api";
88
import { devnet } from "@polkadot-api/descriptors";
99
import { getAliceSigner, getBobSigner, getDevnetApi, waitForFinalizedBlock } from "../src/substrate";
10-
import { forceSetBalanceToEthAddress, setNetworkLastLockCost } from "../src/subtensor";
10+
import { forceSetBalanceToEthAddress, resetNetworkLastLockCost } from "../src/subtensor";
1111
import { decodeAddress } from "@polkadot/util-crypto";
1212
import { u8aToHex } from "@polkadot/util";
1313
import { ILEASING_ADDRESS, ILeasingABI } from "../src/contracts/leasing";
@@ -43,8 +43,7 @@ describe("Test Leasing precompile", () => {
4343
await forceSetBalanceToEthAddress(api, wallet1.address);
4444
await forceSetBalanceToEthAddress(api, wallet2.address);
4545

46-
const defaultNetworkLastLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue()
47-
await setNetworkLastLockCost(api, defaultNetworkLastLockCost);
46+
await resetNetworkLastLockCost(api);
4847
const minLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue();
4948
// guarantee that the crowdloan cap is larger than the deposit
5049
if (minLockCost > crowdloanDeposit) {
@@ -197,7 +196,6 @@ describe("Test Leasing precompile", () => {
197196

198197
let lease = await api.query.SubtensorModule.SubnetLeases.getValue(nextLeaseId);
199198
assert.ok(lease);
200-
201199
const netuid = lease.netuid;
202200

203201
tx = await leaseContract.terminateLease(nextLeaseId, convertH160ToPublicKey(hotkey.address));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("Test staking precompile add remove limit methods", () => {
6262
IStakingV2ABI,
6363
wallet1,
6464
);
65-
await new Promise(resolve => setTimeout(resolve, 1000));
65+
6666
const tx = await contract.addStakeLimit(
6767
hotkey.publicKey,
6868
tao(2000),
@@ -131,7 +131,7 @@ describe("Test staking precompile add remove limit methods", () => {
131131
IStakingV2ABI,
132132
wallet2,
133133
);
134-
await new Promise(resolve => setTimeout(resolve, 1000));
134+
135135
const tx = await contract.addStakeLimit(
136136
hotkey.publicKey,
137137
tao(2000),
@@ -165,7 +165,7 @@ describe("Test staking precompile add remove limit methods", () => {
165165
IStakingV2ABI,
166166
wallet2,
167167
);
168-
await new Promise(resolve => setTimeout(resolve, 1000));
168+
169169
const tx = await contract.removeStakeFull(
170170
hotkey.publicKey,
171171
netuid,

contract-tests/test/staking.precompile.wrap.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import { TypedApi } from "polkadot-api";
55
import {
66
convertH160ToSS58,
77
convertPublicKeyToSs58,
8-
ethAddressToH160,
98
} from "../src/address-utils";
109
import { tao, raoToEth } from "../src/balance-math";
1110
import {
1211
addNewSubnetwork,
13-
addStake,
1412
disableWhiteListCheck,
1513
forceSetBalanceToEthAddress,
1614
forceSetBalanceToSs58Address,
@@ -20,7 +18,6 @@ import { ethers } from "ethers";
2018
import { generateRandomEthersWallet } from "../src/utils";
2119

2220
import { abi, bytecode } from "../src/contracts/stakeWrap";
23-
import { setMaxIdleHTTPParsers } from "http";
2421

2522
describe("Test staking precompile add from deployed contract", () => {
2623
const hotkey = getRandomSubstrateKeypair();
@@ -71,16 +68,13 @@ describe("Test staking precompile add from deployed contract", () => {
7168
wallet1,
7269
);
7370

74-
await new Promise(resolve => setTimeout(resolve, 1000));
7571
const tx = await deployedContract.stake(
7672
hotkey.publicKey,
7773
netuid,
7874
tao(2),
7975
);
8076
await tx.wait();
8177

82-
await new Promise(resolve => setTimeout(resolve, 1000));
83-
8478
const tx2 = await deployedContract.removeStake(
8579
hotkey.publicKey,
8680
netuid,
@@ -92,7 +86,6 @@ describe("Test staking precompile add from deployed contract", () => {
9286

9387
it("Staker add stake limit", async () => {
9488
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1;
95-
let ss58Address = convertH160ToSS58(wallet1.address);
9689

9790
const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet1)
9891
const contract = await contractFactory.deploy()
@@ -109,7 +102,6 @@ describe("Test staking precompile add from deployed contract", () => {
109102
await txResponse.wait();
110103

111104
const balance = await api.query.System.Account.getValue(convertH160ToSS58(contract.target.toString()))
112-
console.log(" == balance is ", balance.data.free)
113105

114106
const deployedContract = new ethers.Contract(
115107
contract.target.toString(),

contract-tests/test/subnet.precompile.hyperparameter.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ describe("Test the Subnet precompile contract", () => {
3030
await disableAdminFreezeWindowAndOwnerHyperparamRateLimit(api)
3131
})
3232

33-
beforeEach(async () => {
34-
await new Promise(resolve => setTimeout(resolve, 500))
35-
})
36-
3733
it("Can register network without identity info", async () => {
3834
const totalNetwork = await api.query.SubtensorModule.TotalNetworks.getValue()
3935

0 commit comments

Comments
 (0)