Skip to content

Commit af73e51

Browse files
committed
add test file
1 parent 48ed380 commit af73e51

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
export const ALPHA_POOL_CONTRACT_ABI = [
2+
{
3+
"inputs": [
4+
{
5+
"internalType": "bytes32",
6+
"name": "_contract_hotkey",
7+
"type": "bytes32"
8+
}
9+
],
10+
"stateMutability": "nonpayable",
11+
"type": "constructor"
12+
},
13+
{
14+
"inputs": [],
15+
"name": "ISTAKING_V2_ADDRESS",
16+
"outputs": [
17+
{
18+
"internalType": "address",
19+
"name": "",
20+
"type": "address"
21+
}
22+
],
23+
"stateMutability": "view",
24+
"type": "function"
25+
},
26+
{
27+
"inputs": [
28+
{
29+
"internalType": "address",
30+
"name": "",
31+
"type": "address"
32+
},
33+
{
34+
"internalType": "uint256",
35+
"name": "",
36+
"type": "uint256"
37+
}
38+
],
39+
"name": "alphaBalance",
40+
"outputs": [
41+
{
42+
"internalType": "uint256",
43+
"name": "",
44+
"type": "uint256"
45+
}
46+
],
47+
"stateMutability": "view",
48+
"type": "function"
49+
},
50+
{
51+
"inputs": [],
52+
"name": "contract_coldkey",
53+
"outputs": [
54+
{
55+
"internalType": "bytes32",
56+
"name": "",
57+
"type": "bytes32"
58+
}
59+
],
60+
"stateMutability": "view",
61+
"type": "function"
62+
},
63+
{
64+
"inputs": [],
65+
"name": "contract_hotkey",
66+
"outputs": [
67+
{
68+
"internalType": "bytes32",
69+
"name": "",
70+
"type": "bytes32"
71+
}
72+
],
73+
"stateMutability": "view",
74+
"type": "function"
75+
},
76+
{
77+
"inputs": [
78+
{
79+
"internalType": "uint256",
80+
"name": "_netuid",
81+
"type": "uint256"
82+
},
83+
{
84+
"internalType": "uint256",
85+
"name": "_alphyAmount",
86+
"type": "uint256"
87+
},
88+
{
89+
"internalType": "bytes32",
90+
"name": "_hotkey",
91+
"type": "bytes32"
92+
}
93+
],
94+
"name": "depositAlpha",
95+
"outputs": [],
96+
"stateMutability": "nonpayable",
97+
"type": "function"
98+
},
99+
{
100+
"inputs": [
101+
{
102+
"internalType": "bytes32",
103+
"name": "_contract_coldkey",
104+
"type": "bytes32"
105+
}
106+
],
107+
"name": "setContractColdkey",
108+
"outputs": [],
109+
"stateMutability": "nonpayable",
110+
"type": "function"
111+
},
112+
{
113+
"inputs": [
114+
{
115+
"internalType": "uint256",
116+
"name": "_netuid",
117+
"type": "uint256"
118+
},
119+
{
120+
"internalType": "uint256",
121+
"name": "_alphyAmount",
122+
"type": "uint256"
123+
},
124+
{
125+
"internalType": "bytes32",
126+
"name": "_user_coldkey",
127+
"type": "bytes32"
128+
}
129+
],
130+
"name": "withdrawAlpha",
131+
"outputs": [],
132+
"stateMutability": "nonpayable",
133+
"type": "function"
134+
}
135+
];
136+
137+
export const ALPHA_POOL_CONTRACT_BYTECODE = "6080604052348015600e575f5ffd5b50604051610d93380380610d938339818101604052810190602e9190606c565b80600181905550506092565b5f5ffd5b5f819050919050565b604e81603e565b81146057575f5ffd5b50565b5f815190506066816047565b92915050565b5f60208284031215607e57607d603a565b5b5f608984828501605a565b91505092915050565b610cf48061009f5f395ff3fe608060405234801561000f575f5ffd5b506004361061007b575f3560e01c8063bee0bca111610059578063bee0bca1146100e9578063d67c076114610105578063f0d6bb8914610123578063fdbcdce91461013f5761007b565b80632849912d1461007f5780633af975ff1461009b57806359948a67146100b9575b5f5ffd5b61009960048036038101906100949190610783565b61015d565b005b6100a3610472565b6040516100b091906107e2565b60405180910390f35b6100d360048036038101906100ce9190610855565b610477565b6040516100e091906108a2565b60405180910390f35b61010360048036038101906100fe9190610783565b610497565b005b61010d610704565b60405161011a91906107e2565b60405180910390f35b61013d600480360381019061013891906108bb565b61070a565b005b610147610713565b60405161015491906108f5565b60405180910390f35b5f5f1b600154036101a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161019a90610968565b60405180910390fd5b5f630e20b25d60e01b5f54838687876040516024016101c6959493929190610986565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090505f61080573ffffffffffffffffffffffffffffffffffffffff165a8360405161024e9190610a29565b5f604051808303818686f4925050503d805f8114610287576040519150601f19603f3d011682016040523d82523d5f602084013e61028c565b606091505b50509050806102d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102c790610a89565b60405180910390fd5b6001548314610409576383f54ead60e01b836001548788886040516024016102fc959493929190610986565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050915061080573ffffffffffffffffffffffffffffffffffffffff165a836040516103839190610a29565b5f604051808303815f8787f1925050503d805f81146103bd576040519150601f19603f3d011682016040523d82523d5f602084013e6103c2565b606091505b50508091505080610408576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ff90610b17565b60405180910390fd5b5b8360025f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8781526020019081526020015f205f8282546104649190610b62565b925050819055505050505050565b5f5481565b6002602052815f5260405f20602052805f5260405f205f91509150505481565b5f5f1b600154036104dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104d490610968565b60405180910390fd5b8160025f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8581526020019081526020015f2054101561056c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161056390610c05565b60405180910390fd5b8160025f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8581526020019081526020015f205f8282546105c79190610c23565b925050819055505f630e20b25d60e01b826001548687876040516024016105f2959493929190610986565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090505f61080573ffffffffffffffffffffffffffffffffffffffff165a8360405161067a9190610a29565b5f604051808303815f8787f1925050503d805f81146106b4576040519150601f19603f3d011682016040523d82523d5f602084013e6106b9565b606091505b50509050806106fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106f490610ca0565b60405180910390fd5b5050505050565b60015481565b805f8190555050565b61080581565b5f5ffd5b5f819050919050565b61072f8161071d565b8114610739575f5ffd5b50565b5f8135905061074a81610726565b92915050565b5f819050919050565b61076281610750565b811461076c575f5ffd5b50565b5f8135905061077d81610759565b92915050565b5f5f5f6060848603121561079a57610799610719565b5b5f6107a78682870161073c565b93505060206107b88682870161073c565b92505060406107c98682870161076f565b9150509250925092565b6107dc81610750565b82525050565b5f6020820190506107f55f8301846107d3565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610824826107fb565b9050919050565b6108348161081a565b811461083e575f5ffd5b50565b5f8135905061084f8161082b565b92915050565b5f5f6040838503121561086b5761086a610719565b5b5f61087885828601610841565b92505060206108898582860161073c565b9150509250929050565b61089c8161071d565b82525050565b5f6020820190506108b55f830184610893565b92915050565b5f602082840312156108d0576108cf610719565b5b5f6108dd8482850161076f565b91505092915050565b6108ef8161081a565b82525050565b5f6020820190506109085f8301846108e6565b92915050565b5f82825260208201905092915050565b7f636f6e747261637420636f6c646b6579206e6f742073657400000000000000005f82015250565b5f61095260188361090e565b915061095d8261091e565b602082019050919050565b5f6020820190508181035f83015261097f81610946565b9050919050565b5f60a0820190506109995f8301886107d3565b6109a660208301876107d3565b6109b36040830186610893565b6109c06060830185610893565b6109cd6080830184610893565b9695505050505050565b5f81519050919050565b5f81905092915050565b8281835e5f83830152505050565b5f610a03826109d7565b610a0d81856109e1565b9350610a1d8185602086016109eb565b80840191505092915050565b5f610a3482846109f9565b915081905092915050565b7f75736572206465706f73697420616c7068612063616c6c206661696c656400005f82015250565b5f610a73601e8361090e565b9150610a7e82610a3f565b602082019050919050565b5f6020820190508181035f830152610aa081610a67565b9050919050565b7f75736572206465706f7369742c206d6f7665207374616b652063616c6c2066615f8201527f696c656400000000000000000000000000000000000000000000000000000000602082015250565b5f610b0160248361090e565b9150610b0c82610aa7565b604082019050919050565b5f6020820190508181035f830152610b2e81610af5565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610b6c8261071d565b9150610b778361071d565b9250828201905080821115610b8f57610b8e610b35565b5b92915050565b7f757365722077697468647261772c20696e73756666696369656e7420616c70685f8201527f612062616c616e63650000000000000000000000000000000000000000000000602082015250565b5f610bef60298361090e565b9150610bfa82610b95565b604082019050919050565b5f6020820190508181035f830152610c1c81610be3565b9050919050565b5f610c2d8261071d565b9150610c388361071d565b9250828203905081811115610c5057610c4f610b35565b5b92915050565b7f7573657220776974686472617720616c7068612063616c6c206661696c6564005f82015250565b5f610c8a601f8361090e565b9150610c9582610c56565b602082019050919050565b5f6020820190508181035f830152610cb781610c7e565b905091905056fea2646970667358221220f45d4ef5e97ebc9ba47e080444392e6e59f1b327de53eb440f72a72dea39fc1864736f6c634300081e0033";

evm-tests/test/alphaPool.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as assert from "assert";
2+
import * as chai from "chai";
3+
4+
import { getDevnetApi } from "../src/substrate"
5+
import { generateRandomEthersWallet, getPublicClient } from "../src/utils";
6+
import { ETH_LOCAL_URL } from "../src/config";
7+
import { devnet } from "@polkadot-api/descriptors"
8+
import { PublicClient } from "viem";
9+
import { TypedApi } from "polkadot-api";
10+
import { ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE } from "../src/contracts/alphaPool";
11+
import { toViemAddress } from "../src/address-utils";
12+
import { forceSetBalanceToEthAddress, disableWhiteListCheck } from "../src/subtensor";
13+
import { ethers } from "ethers"
14+
describe("bridge token contract deployment", () => {
15+
// init eth part
16+
const wallet = generateRandomEthersWallet();
17+
let publicClient: PublicClient;
18+
19+
// init substrate part
20+
let api: TypedApi<typeof devnet>
21+
22+
before(async () => {
23+
// init variables got from await and async
24+
publicClient = await getPublicClient(ETH_LOCAL_URL)
25+
api = await getDevnetApi()
26+
27+
await forceSetBalanceToEthAddress(api, wallet.address)
28+
await disableWhiteListCheck(api, true)
29+
});
30+
31+
it("Can deploy bridge token smart contract", async () => {
32+
const contractFactory = new ethers.ContractFactory(ALPHA_POOL_CONTRACT_ABI, ALPHA_POOL_CONTRACT_BYTECODE, wallet)
33+
const contract = await contractFactory.deploy("name",
34+
"symbol", wallet.address)
35+
await contract.waitForDeployment()
36+
assert.notEqual(contract.target, undefined)
37+
38+
const contractAddress = contract.target.toString()
39+
40+
const code = await publicClient.getCode({ address: toViemAddress(contractAddress) })
41+
if (code === undefined) {
42+
throw new Error("code not available")
43+
}
44+
assert.ok(code.length > 100)
45+
assert.ok(code.includes("0x60806040523480156"))
46+
});
47+
48+
});

0 commit comments

Comments
 (0)