Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
submitRinghash function refine, add batchSumbitRinghash function. #111,
Browse files Browse the repository at this point in the history
  • Loading branch information
kongliangzhong committed Nov 10, 2017
1 parent 31692b3 commit 4b4a5df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
27 changes: 16 additions & 11 deletions contracts/RinghashRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,32 @@ contract RinghashRegistry {
////////////////////////////////////////////////////////////////////////////

function submitRinghash(
uint ringSize,
address ringminer,
uint8[] vList,
bytes32[] rList,
bytes32[] sList
bytes32 ringhash
)
public
{
bytes32 ringhash = calculateRinghash(
ringSize,
vList,
rList,
sList
);

require(canSubmit(ringhash, ringminer)); //, "Ringhash submitted");

submissions[ringhash] = Submission(ringminer, block.number);
RinghashSubmitted(ringminer, ringhash);
}

function batchSubmitRinghash(
address[] ringminerList,
bytes32[] ringhashList
)
public
{
uint size = ringminerList.length;
require(size > 0);
require(size == ringhashList.length);

for (uint i = 0; i < size; i++) {
submitRinghash(ringminerList[i], ringhashList[i]);
}
}

/// @dev Calculate the hash of a ring.
function calculateRinghash(
uint ringSize,
Expand Down
26 changes: 15 additions & 11 deletions test/testRinghashRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ contract("RinghashRegistry", (accounts: string[]) => {
it("should be able to submit a ring hash", async () => {
const ring = await ringFactory.generateSize2Ring01(order1Owner, order2Owner, ringOwner);
const p = ringFactory.ringToSubmitableParams(ring, [0, 0], feeRecepient);
const ringHash = ring.getRingHashHex();

const tx = await ringhashRegistry.submitRinghash(2,
ringOwner,
p.vList,
p.rList,
p.sList);
const tx = await ringhashRegistry.submitRinghash(ringOwner, ringHash);

const ringHash = ring.getRingHashHex();
const isReserved = await ringhashRegistry.isReserved(ringHash, ringOwner);
assert.equal(isReserved, true, "ring hash not found after summitted");
});
Expand All @@ -84,17 +80,25 @@ contract("RinghashRegistry", (accounts: string[]) => {
assert.equal(canSubmit2, false, "can submit again after summitted by another address");
});

it("should be able to submit ringhashs in batch", async () => {
const ringminerList = [accounts[0], accounts[2], accounts[3]];
const ringhashList = ["0xabc", "0x12ab", "0xcb4d3"]; // mock ringhashList.
const tx = await ringhashRegistry.batchSubmitRinghash(ringminerList, ringhashList);

for (let i = 0; i < ringminerList.length; i++) {
const isReserved = await ringhashRegistry.isReserved(ringhashList[i], ringminerList[i]);
assert.equal(isReserved, true, "ring hash not found after summitted");
}
});

it(`should not be able to submit a ring hash by a different ringminer
if the same hash has submmitted within 100 blocks`, async () => {
try {
const ring = await ringFactory.generateSize2Ring01(order1Owner, order2Owner, ringOwner);
const p = ringFactory.ringToSubmitableParams(ring, [0, 0], feeRecepient);
const ringHash = ring.getRingHashHex();

const tx = await ringhashRegistry.submitRinghash(2,
ringOwner,
p.vList,
p.rList,
p.sList);
const tx = await ringhashRegistry.submitRinghash(ringOwner, ringHash);
} catch (err) {
const errMsg = `${err}`;
assert(_.includes(errMsg, "Error: VM Exception while processing transaction: revert"),
Expand Down

0 comments on commit 4b4a5df

Please sign in to comment.