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

Commit

Permalink
fix a bug in NameRegistry contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kongliangzhong committed Mar 22, 2018
1 parent 1a53b9a commit edd3133
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/NameRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ contract NameRegistry {
returns (bytes12 result)
{
assembly {
result := mload(add(str, 12))
result := mload(add(str, 32))
}
}

Expand Down
26 changes: 26 additions & 0 deletions test/testNameRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {

contract("NameRegistry", (accounts: string[]) => {
const user = accounts[1];
const user2 = accounts[2];

let nameRegistry: any;

Expand All @@ -25,6 +26,31 @@ contract("NameRegistry", (accounts: string[]) => {
assert.equal(name, nameRegistried);
});

it("is able to register a different name", async () => {
const name = "test003";
await nameRegistry.registerName(name, {from: user2});
const nameOwner = await nameRegistry.getOwner(name);
// console.log("nameOwner:", nameOwner);
assert.equal(user2, nameOwner);

const nameRegistried = await nameRegistry.nameMap(user2);
assert.equal(name, nameRegistried);
});

it("is able to add a participant pair after name had been registeried", async () => {
const name = "test002";
const name2 = "test003";
await nameRegistry.addParticipant(user, user, {from: user});
const pids = await nameRegistry.getParticipantIds(name, 0, 1);
const pid1 = pids[0].toNumber();

await nameRegistry.addParticipant(user2, user2, {from: user2});
const pids2 = await nameRegistry.getParticipantIds(name2, 0, 1);
const pid2 = pids2[0].toNumber();

assert.equal(pid1 + 1, pid2, "pid not increased correctly.");
});

});

});

0 comments on commit edd3133

Please sign in to comment.