Skip to content

Commit

Permalink
Merge pull request #1 from opentensor/add-proxy-tests
Browse files Browse the repository at this point in the history
Add staking proxy test
  • Loading branch information
gztensor authored Jan 15, 2025
2 parents 1017350 + 622fb56 commit b84b437
Showing 1 changed file with 93 additions and 33 deletions.
126 changes: 93 additions & 33 deletions src/evm/eth.staking.precompile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,74 +21,100 @@ let fundedEthWallet = generateRandomAddress();

let abi = [
{
"inputs": [
inputs: [
{
internalType: "bytes32",
name: "delegate",
type: "bytes32"
}
],
name: "addProxy",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
"internalType": "bytes32",
"name": "hotkey",
"type": "bytes32"
internalType: "bytes32",
name: "hotkey",
type: "bytes32"
},
{
"internalType": "uint256",
"name": "netuid",
"type": "uint256"
internalType: "uint256",
name: "netuid",
type: "uint256"
}
],
"name": "addStake",
"outputs": [],
"stateMutability": "payable",
"type": "function"
name: "addStake",
outputs: [],
stateMutability: "payable",
type: "function"
},
{
inputs: [
{
internalType: "bytes32",
name: "delegate",
type: "bytes32"
}
],
name: "removeProxy",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "bytes32",
name: "hotkey",
type: "bytes32",
type: "bytes32"
},
{
internalType: "bytes32",
name: "coldkey",
type: "bytes32",
type: "bytes32"
},
{
"internalType": "uint256",
"name": "netuid",
"type": "uint256"
internalType: "uint256",
name: "netuid",
type: "uint256"
}
],
name: "getStake",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
type: "uint256"
}
],
stateMutability: "view",
type: "function",
type: "function"
},
{
"inputs": [
inputs: [
{
"internalType": "bytes32",
"name": "hotkey",
"type": "bytes32"
internalType: "bytes32",
name: "hotkey",
type: "bytes32"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
internalType: "uint256",
name: "amount",
type: "uint256"
},
{
"internalType": "uint256",
"name": "netuid",
"type": "uint256"
internalType: "uint256",
name: "netuid",
type: "uint256"
}
],
"name": "removeStake",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
name: "removeStake",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
];

Expand Down Expand Up @@ -296,4 +322,38 @@ describe.only("Staking precompile", () => {
});
});
});

it("Can add/remove proxy", async () => {
await usingEthApi(async (provider) => {
// add/remove are done in a single test case, because we can't use the same private/public key
// between substrate and EVM, but to test the remove part, we must predefine the proxy first.
// it makes `remove` being dependent on `add`, because we should use `addProxy` from contract
// to prepare the proxy for `removeProxy` testing - the proxy is specified for the
// caller/origin.

// first, check we don't have proxies
const publicKey = convertH160ToPublicKey(fundedEthWallet.address);
let proxies = await api.query.proxy.proxies(publicKey);
expect(proxies[0].length).to.be.eq(0);

// intialize the contract
const signer = new ethers.Wallet(fundedEthWallet.privateKey, provider);
const contract = new ethers.Contract(address, abi, signer);

// test "add"
let tx = await contract.addProxy(tk.bob.publicKey);
await tx.wait();

const [[{ delegate }]] = await api.query.proxy.proxies(publicKey);

expect(delegate.toHuman()).to.be.eq(tk.bob.address);

// test "remove"
tx = await contract.removeProxy(tk.bob.publicKey);
await tx.wait();

proxies = await api.query.proxy.proxies(publicKey);
expect(proxies[0].length).to.be.eq(0);
});
});
});

0 comments on commit b84b437

Please sign in to comment.