Skip to content

Commit

Permalink
Merge pull request #17 from HarryR/split-tests-gas-reporting
Browse files Browse the repository at this point in the history
Split tests into deposit/withdraw, updated dependencies
  • Loading branch information
HarryR committed Jul 22, 2019
2 parents 82f093b + 8a39fa3 commit 1b9fbef
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
11 changes: 6 additions & 5 deletions solidity/package.json
Expand Up @@ -7,17 +7,18 @@
"author": "HarryR@noreply.users.gihub.com",
"license": "GPL-3.0+",
"dependencies": {
"solc": "^0.5.3",
"truffle": "^5.0.2"
"solc": "^0.5.10",
"truffle": "^5.0.28"
},
"devDependencies": {
"bn.js": "^4.11.8",
"bn.js": "^5.0.0",
"ffi": "github:lxe/node-ffi#node-12",
"ganache-cli": "^6.2.5",
"ganache-cli": "^6.5.0",
"ref": "github:lxe/ref#node-12",
"ref-array": "github:lxe/ref-array#node-12",
"solhint": "^1.5.0",
"solidity-coverage": "^0.5.11"
"solidity-coverage": "^0.6.3",
"eth-gas-reporter": "^0.2.6"
},
"scripts": {
"compile": "truffle compile",
Expand Down
41 changes: 26 additions & 15 deletions solidity/test/TestMiximus.js
Expand Up @@ -87,35 +87,46 @@ let proof_to_flat = (proof) => {

contract("TestableMiximus", () => {
describe("Deposit", () => {
it("deposits then withdraws", async () => {
let obj = await TestableMiximus.deployed();
let obj;
let secret;
let leaf_hash;
let proof_root;
let nullifier;
let proof;
let new_root_and_offset;

it("gets ready for deposit", async () => {
obj = await TestableMiximus.deployed();

// Parameters for deposit
let secret = new BN(crypto.randomBytes(30).toString("hex"), 16);
let leaf_hash = await obj.MakeLeafHash.call(secret);
secret = new BN(crypto.randomBytes(30).toString("hex"), 16);
leaf_hash = await obj.MakeLeafHash.call(secret);

// Perform deposit
let new_root_and_offset = await obj.Deposit.call(leaf_hash, {value: 1000000000000000000});
await obj.Deposit.sendTransaction(leaf_hash, {value: 1000000000000000000});
new_root_and_offset = await obj.Deposit.call(leaf_hash, {value: 1000000000000000000});
});

it("deposits", async () => {
await obj.Deposit.sendTransaction(leaf_hash, {value: 1000000000000000000});
});

it("construct arguments for withdraw", async () => {
// TODO: verify amount has been transferred


// Build parameters for proving
let tmp = await obj.GetPath.call(new_root_and_offset[1]);
let proof_address = tmp[1].map((_) => _ ? "1" : "0").join("");
let proof_path = [];
for( var i = 0; i < proof_address.length; i++ ) {
proof_path.push( "0x" + tmp[0][i].toString(16) );
}
let proof_root = await obj.GetRoot.call();
proof_root = await obj.GetRoot.call();
// TODO: verify proof root equals expected one
proof_root = new_root_and_offset[0];
let leaf_index = new_root_and_offset[1];
let proof_exthash = await obj.GetExtHash.call();

// Calcuate our nullifier, so we can verify the proof matches what is expected
let nullifier = libmiximus.miximus_nullifier(secret.toString(10), leaf_index.toString(10));
nullifier = libmiximus.miximus_nullifier(secret.toString(10), leaf_index.toString(10));
let proof_pub_hash = await obj.HashPublicInputs.call(proof_root, nullifier, proof_exthash);

// Run prover to generate proof
Expand All @@ -131,7 +142,7 @@ contract("TestableMiximus", () => {

// There *must* be JSON returned, containing the valid proof
assert.notStrictEqual(proof_json, null);
let proof = JSON.parse(proof_json);
proof = JSON.parse(proof_json);

// Ensure proof inputs match what is expected
assert.strictEqual("0x" + proof_pub_hash.toString(16), proof.input[0]);
Expand Down Expand Up @@ -170,20 +181,20 @@ contract("TestableMiximus", () => {
// Verify nullifier doesn't exist
let is_spent_b4_withdraw = await obj.IsSpent(nullifier.toString(10));
assert.strictEqual(is_spent_b4_withdraw, false);
});


it("withdraws", async () => {
// Then perform the withdraw
await obj.Withdraw(
proof_root.toString(10),
nullifier.toString(10),
proof_to_flat(proof));
});


it("nullifier exists after withdraw", async () => {
// Verify nullifier exists
let is_spent = await obj.IsSpent(nullifier.toString(10));
assert.strictEqual(is_spent, true);


// TODO: verify balance has been increased
});
});
Expand Down
6 changes: 6 additions & 0 deletions solidity/truffle.js
Expand Up @@ -18,5 +18,11 @@ module.exports = {
enabled: true,
runs: 200
}
},
mocha: {
reporter: 'eth-gas-reporter',
reporterOptions: {
onlyCalledMethods: false
}
}
}

0 comments on commit 1b9fbef

Please sign in to comment.