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
3 changes: 2 additions & 1 deletion contract-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"@polkadot-api/sdk-ink": "^0.5.1",
"@polkadot-labs/hdkd": "^0.0.25",
"@polkadot-labs/hdkd-helpers": "^0.0.25",
"@polkadot/api": "^16.4.6",
"@polkadot/util-crypto": "^14.0.1",
"@types/mocha": "^10.0.10",
"dotenv": "17.2.1",
"ethers": "^6.13.5",
"mocha": "^11.1.0",
"polkadot-api": "^1.22.0",
"@polkadot/api": "^16.4.6",
"rxjs": "^7.8.2",
"scale-ts": "^1.6.1",
"viem": "2.23.4",
Expand Down
41 changes: 40 additions & 1 deletion contract-tests/test/runtime.call.precompile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PublicClient } from "viem";
import { PolkadotSigner, TypedApi, getTypedCodecs } from "polkadot-api";
import { convertPublicKeyToSs58 } from "../src/address-utils"
import { forceSetBalanceToEthAddress, setMaxChildkeyTake, burnedRegister, forceSetBalanceToSs58Address, addStake, setTxRateLimit, addNewSubnetwork, startCall, setTempo } from "../src/subtensor";
import { xxhashAsHex } from "@polkadot/util-crypto";

describe("Test the dispatch precompile", () => {
let publicClient: PublicClient;
Expand Down Expand Up @@ -62,6 +63,45 @@ describe("Test the dispatch precompile", () => {
assert.equal(aliceBalance + transferAmount, aliceBalanceAfterTransfer)
})

it("Storage query only allow some pallets prefixed storage", async () => {
const authorizedKeys = [
await api.query.SubtensorModule.TotalNetworks.getKey(),
await api.query.Swap.AlphaSqrtPrice.getKey(),
await api.query.Balances.TotalIssuance.getKey(),
await api.query.Proxy.Announcements.getKey(),
await api.query.Scheduler.Agenda.getKey(),
await api.query.Drand.Pulses.getKey(),
await api.query.Crowdloan.Crowdloans.getKey(),
await api.query.Sudo.Key.getKey(),
await api.query.Multisig.Multisigs.getKey(),
await api.query.Timestamp.Now.getKey(),
];

for (const key of authorizedKeys) {
await assert.doesNotReject(
publicClient.call({
to: ISTORAGE_QUERY_ADDRESS,
data: key.toString() as `0x${string}`,
})
);
}

const unauthorizedKeys = [
await api.query.System.Events.getKey(),
await api.query.Grandpa.CurrentSetId.getKey(),
xxhashAsHex(":code" , 128),
];

for (const key of unauthorizedKeys) {
await assert.rejects(
publicClient.call({
to: ISTORAGE_QUERY_ADDRESS,
data: key.toString() as `0x${string}`,
})
);
}
})


it("Value type storage query call via precompile contract works correctly", async () => {
const key = await api.query.SubtensorModule.MaxChildkeyTake.getKey();
Expand Down Expand Up @@ -112,7 +152,6 @@ describe("Test the dispatch precompile", () => {
const totalHotkeyAlphaValueCodec = codec.query.SubtensorModule.TotalHotkeyAlpha.value;
const decodedValue = totalHotkeyAlphaValueCodec.dec(rawResultData);
assert.equal(totalHotkeyAlphaOnChain, decodedValue, "value should be the same as on chain")

})

// Polkadot api can't decode the boolean type for now.
Expand Down
Loading
Loading