Skip to content
Merged
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
6 changes: 6 additions & 0 deletions evm-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ between runtime and precompile contracts.

## polkadot api

You need `polkadot-api` globally installed:

```bash
$ npm i -g polkadot-api
```

To get the metadata, you need start the localnet via run
`./scripts/localnet.sh`. then run following command to get metadata, a folder
name .papi will be created, which include the metadata and type definitions.
Expand Down
18 changes: 16 additions & 2 deletions evm-tests/test/neuron.precompile.reveal-weights.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from "assert";
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair, waitForTransactionWithRetry } from "../src/substrate"
import { devnet } from "@polkadot-api/descriptors"
import { PolkadotSigner, TypedApi } from "polkadot-api";
import { convertPublicKeyToSs58, convertH160ToSS58 } from "../src/address-utils"
Expand Down Expand Up @@ -70,6 +70,20 @@ describe("Test neuron precompile reveal weights", () => {
await startCall(api, netuid, coldkey)

console.log("test the case on subnet ", netuid)
// Disable admin freeze window and owner hyperparam rate limiting for tests
{
const alice = getAliceSigner()

// Set AdminFreezeWindow to 0
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)

// Set OwnerHyperparamRateLimit to 0
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
}

await setWeightsSetRateLimit(api, netuid, BigInt(0))

Expand Down Expand Up @@ -164,4 +178,4 @@ describe("Test neuron precompile reveal weights", () => {
assert.ok(weight[1] !== undefined)
}
})
});
});
18 changes: 16 additions & 2 deletions evm-tests/test/neuron.precompile.set-weights.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from "assert";

import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair, waitForTransactionWithRetry } from "../src/substrate"
import { devnet } from "@polkadot-api/descriptors"
import { TypedApi } from "polkadot-api";
import { convertH160ToSS58, convertPublicKeyToSs58, } from "../src/address-utils"
Expand Down Expand Up @@ -38,6 +38,20 @@ describe("Test neuron precompile contract, set weights function", () => {
await burnedRegister(api, netuid, convertH160ToSS58(wallet.address), coldkey)
const uid = await api.query.SubtensorModule.Uids.getValue(netuid, convertH160ToSS58(wallet.address))
assert.notEqual(uid, undefined)
// Disable admin freeze window and owner hyperparam rate limiting for tests
{
const alice = getAliceSigner()

// Set AdminFreezeWindow to 0
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)

// Set OwnerHyperparamRateLimit to 0
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
}
// disable reveal and enable direct set weights
await setCommitRevealWeightsEnabled(api, netuid, false)
await setWeightsSetRateLimit(api, netuid, BigInt(0))
Expand Down Expand Up @@ -68,4 +82,4 @@ describe("Test neuron precompile contract, set weights function", () => {
});
}
})
});
});
16 changes: 15 additions & 1 deletion evm-tests/test/staking.precompile.reward.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from "assert";
import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair, waitForTransactionWithRetry } from "../src/substrate"
import { devnet } from "@polkadot-api/descriptors"
import { TypedApi } from "polkadot-api";
import { convertPublicKeyToSs58 } from "../src/address-utils"
Expand Down Expand Up @@ -39,6 +39,20 @@ describe("Test neuron precompile reward", () => {
await startCall(api, netuid, coldkey)

console.log("test the case on subnet ", netuid)
// Disable admin freeze window and owner hyperparam rate limiting for tests
{
const alice = getAliceSigner()

// Set AdminFreezeWindow to 0
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)

// Set OwnerHyperparamRateLimit to 0
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
}

await setTxRateLimit(api, BigInt(0))
await setTempo(api, root_netuid, root_tempo)
Expand Down
2 changes: 1 addition & 1 deletion evm-tests/test/staking.precompile.stake-get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("Test staking precompile get methods", () => {
await contract.getStake(hotkey.publicKey, coldkey.publicKey, netuid)
);

// validator returned as bigint now.
// validator returned as bigint now.
const validators =
await contract.getAlphaStakedValidators(hotkey.publicKey, netuid)

Expand Down
17 changes: 16 additions & 1 deletion evm-tests/test/subnet.precompile.hyperparameter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from "assert";

import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
import { getDevnetApi, getRandomSubstrateKeypair, getAliceSigner, waitForTransactionWithRetry } from "../src/substrate"
import { devnet } from "@polkadot-api/descriptors"
import { TypedApi } from "polkadot-api";
import { convertPublicKeyToSs58 } from "../src/address-utils"
Expand All @@ -25,6 +25,21 @@ describe("Test the Subnet precompile contract", () => {
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey1.publicKey))
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey2.publicKey))
await forceSetBalanceToEthAddress(api, wallet.address)

// Disable admin freeze window and owner hyperparam rate limiting for tests
{
const alice = getAliceSigner()

// Set AdminFreezeWindow to 0
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)

// Set OwnerHyperparamRateLimit to 0
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
}
})

it("Can register network without identity info", async () => {
Expand Down
12 changes: 12 additions & 0 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ mod benchmarks {
_(RawOrigin::Root, 5u16/*version*/)/*sudo_set_commit_reveal_version()*/;
}

#[benchmark]
fn sudo_set_admin_freeze_window() {
#[extrinsic_call]
_(RawOrigin::Root, 5u16/*window*/)/*sudo_set_admin_freeze_window*/;
}

#[benchmark]
fn sudo_set_owner_hparam_rate_limit() {
#[extrinsic_call]
_(RawOrigin::Root, 10u64/*limit*/)/*sudo_set_owner_hparam_rate_limit*/;
}

#[benchmark]
fn sudo_set_owner_immune_neuron_limit() {
pallet_subtensor::Pallet::<T>::init_new_network(
Expand Down
Loading
Loading