Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions contract-tests/src/subtensor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as assert from "assert";
import { devnet, MultiAddress } from '@polkadot-api/descriptors';
import { TypedApi, TxCallData, Binary, Enum } from 'polkadot-api';
import { TypedApi, TxCallData, Binary, Enum, getTypedCodecs } from 'polkadot-api';
import { KeyPair } from "@polkadot-labs/hdkd-helpers"
import { getAliceSigner, waitForTransactionCompletion, getSignerFromKeypair, waitForTransactionWithRetry } from './substrate'
import { convertH160ToSS58, convertPublicKeyToSs58, ethAddressToH160 } from './address-utils'
import { tao } from './balance-math'
import internal from "stream";
import { createCodec } from "scale-ts";

// create a new subnet and return netuid
export async function addNewSubnetwork(api: TypedApi<typeof devnet>, hotkey: KeyPair, coldkey: KeyPair) {
Expand All @@ -26,6 +27,9 @@ export async function addNewSubnetwork(api: TypedApi<typeof devnet>, hotkey: Key
const newTotalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue()
// could create multiple subnetworks during retry, just return the first created one
assert.ok(newTotalNetworks > totalNetworks)

// rewrite network last lock cost to 0, to avoid the lock cost calculation error
await setNetworkLastLockCost(api)
return totalNetworks
}

Expand Down Expand Up @@ -398,4 +402,19 @@ export async function sendWasmContractExtrinsic(api: TypedApi<typeof devnet>, co
storage_deposit_limit: BigInt(1000000000)
})
await waitForTransactionWithRetry(api, tx, signer)
}
}

export async function setNetworkLastLockCost(api: TypedApi<typeof devnet>) {
const alice = getAliceSigner()
const key = await api.query.SubtensorModule.NetworkLastLockCost.getKey()
const codec = await getTypedCodecs(devnet);
const value = codec.query.SubtensorModule.NetworkLastLockCost.value.enc(BigInt(0))
const internalCall = api.tx.System.set_storage({
items: [[Binary.fromHex(key), Binary.fromBytes(value)]]
})
const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall })
await waitForTransactionWithRetry(api, tx, alice)

const valueOnChain = await api.query.SubtensorModule.NetworkLastLockCost.getValue()
assert.equal(BigInt(0), valueOnChain)
}
4 changes: 2 additions & 2 deletions contract-tests/test/votingPower.precompile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ describe("Test VotingPower Precompile", () => {

assert.ok(alpha !== undefined, "getVotingPowerEmaAlpha should return a value");
assert.strictEqual(typeof alpha, 'bigint', "getVotingPowerEmaAlpha should return a bigint");
// Default alpha is 0.1 * 10^18 = 100_000_000_000_000_000
assert.strictEqual(alpha, BigInt("100000000000000000"), "Default alpha should be 0.1 (100_000_000_000_000_000)");
// Default alpha is 0_003_570_000_000_000_000 // 0.00357 * 10^18 = 2 weeks e-folding (time-constant) @ 361
assert.strictEqual(alpha, BigInt("3570000000000000"), "Default alpha should be 0.00357 * 10^18 (3570000000000000)");
});
});

Expand Down
Loading