mirror of
https://github.com/arnaucube/miksi-core.git
synced 2026-02-07 03:26:41 +01:00
Add ETH deposit & withdraw
This commit is contained in:
@@ -15,9 +15,9 @@ contract("miksi", (accounts) => {
|
||||
|
||||
const {
|
||||
0: owner,
|
||||
1: idEth1,
|
||||
2: idEth2,
|
||||
3: idEth3,
|
||||
1: addr1, // used for the deposit
|
||||
2: addr2, // used for the withdraw
|
||||
3: addr3,
|
||||
} = accounts;
|
||||
|
||||
let insVerifier;
|
||||
@@ -32,14 +32,24 @@ contract("miksi", (accounts) => {
|
||||
it("miksi flow", async () => {
|
||||
const secret = "123456789";
|
||||
|
||||
const coinCode = "1";
|
||||
const amount = "100";
|
||||
const coinCode = "0"; // refearing to ETH
|
||||
const ethAmount = '0.5';
|
||||
const amount = web3.utils.toWei(ethAmount, 'ether');
|
||||
|
||||
let balance_wei = await web3.eth.getBalance(addr1);
|
||||
console.log("Balance at " + addr1, web3.utils.fromWei(balance_wei, 'ether'));
|
||||
expect(balance_wei).to.be.equal('100000000000000000000');
|
||||
|
||||
const poseidon = circomlib.poseidon.createHash(6, 8, 57);
|
||||
const commitment = poseidon([coinCode, amount, secret]).toString();
|
||||
|
||||
// deposit
|
||||
await insMiksi.deposit(coinCode, amount, commitment);
|
||||
console.log("Deposit of " + ethAmount + " ETH from " + addr1);
|
||||
await insMiksi.deposit(coinCode, commitment, {from: addr1, value: amount});
|
||||
|
||||
balance_wei = await web3.eth.getBalance(addr1);
|
||||
console.log("Balance at " + addr1, web3.utils.fromWei(balance_wei, 'ether'));
|
||||
expect(balance_wei).to.be.equal('99499141300000000000');
|
||||
|
||||
// getDeposit data
|
||||
const res = await insMiksi.getDeposit(commitment);
|
||||
@@ -53,9 +63,11 @@ contract("miksi", (accounts) => {
|
||||
"coinCode": coinCode,
|
||||
"amount": amount,
|
||||
"commitment": commitment,
|
||||
"secret": secret
|
||||
"secret": secret,
|
||||
"address": addr2
|
||||
});
|
||||
const options = {};
|
||||
console.log("Calculate witness");
|
||||
const wc = await WitnessCalculatorBuilder(wasm, options);
|
||||
const w = await wc.calculateWitness(input);
|
||||
const witness = unstringifyBigInts(stringifyBigInts(w));
|
||||
@@ -63,11 +75,14 @@ contract("miksi", (accounts) => {
|
||||
// generate zkproof of commitment using snarkjs (as is a test)
|
||||
const provingKey = unstringifyBigInts(JSON.parse(fs.readFileSync("./build/proving_key.json", "utf8")));
|
||||
|
||||
console.log("Generate zkSNARK proof");
|
||||
const {proof, publicSignals} = groth.genProof(provingKey, witness);
|
||||
|
||||
// withdraw
|
||||
console.log("Withdraw of " + ethAmount + " ETH to " + addr2);
|
||||
const resW = await insMiksi.withdraw(
|
||||
commitment,
|
||||
addr2,
|
||||
[proof.pi_a[0].toString(), proof.pi_a[1].toString()],
|
||||
[
|
||||
[proof.pi_b[0][1].toString(), proof.pi_b[0][0].toString()],
|
||||
@@ -75,7 +90,10 @@ contract("miksi", (accounts) => {
|
||||
],
|
||||
[proof.pi_c[0].toString(), proof.pi_c[1].toString()]
|
||||
);
|
||||
console.log("resW", resW);
|
||||
// console.log("resW", resW);
|
||||
|
||||
balance_wei = await web3.eth.getBalance(addr2);
|
||||
console.log("Balance at " + addr2, web3.utils.fromWei(balance_wei, 'ether'));
|
||||
expect(balance_wei).to.be.equal('100500000000000000000');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user