Skip to content

Commit

Permalink
Merge pull request #560 from gulshanvasnani/gulshan/gh_556_only_organ…
Browse files Browse the repository at this point in the history
…ization_should_anchor_stateroot

Only organization should anchor state roots
  • Loading branch information
0xsarvesh authored Dec 21, 2018
2 parents 6672548 + 7d15432 commit 37870e6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion contracts/gateway/Anchor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ contract Anchor is StateRootInterface, Organized, CircularBufferUint {
bytes32 _stateRoot
)
external
onlyWorker
onlyOrganization
returns (bool success_)
{
// State root should be valid
Expand Down
1 change: 0 additions & 1 deletion contracts/gateway/GatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pragma solidity ^0.5.0;
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Origin Chain: Gateway Contract
//
// http://www.simpletoken.org/
//
Expand Down
21 changes: 11 additions & 10 deletions test/gateway/anchor/anchor_state_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
),
'State root must not be zero.',
);
Expand All @@ -86,7 +86,7 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
),
'Given block height is lower or equal to highest anchored state root block height.',
);
Expand All @@ -100,24 +100,25 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
),
'Given block height is lower or equal to highest anchored state root block height.',
);

});

it('should fail when caller is not worker address', async () => {
it('should fail when caller is not owner address', async () => {

blockHeight = blockHeight.addn(1);
let nonOwner = accounts[6];

await Utils.expectRevert(
anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: accounts[6]},
{from: nonOwner},
),
'Only whitelisted workers are allowed to call this method.',
'Only the organization is allowed to call this method.',
);

});
Expand All @@ -129,7 +130,7 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
let result = await anchor.anchorStateRoot.call(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
);

assert.strictEqual(
Expand All @@ -141,7 +142,7 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
await anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
);

let latestBlockHeight = await anchor.getLatestStateRootBlockHeight.call();
Expand All @@ -167,7 +168,7 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
let tx = await anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
);

let event = EventDecoder.getEvents(tx, anchor);
Expand Down Expand Up @@ -206,7 +207,7 @@ contract('Anchor.anchorStateRoot()', function (accounts) {
await anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
);

// Check that the older state root has been deleted when i > max state roots.
Expand Down
2 changes: 1 addition & 1 deletion test/gateway/anchor/get_latest_state_root_block_height.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract('Anchor.getLatestStateRootBlockHeight()', function (accounts) {
await anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
);

let latestBlockHeight = await anchor.getLatestStateRootBlockHeight.call();
Expand Down
2 changes: 1 addition & 1 deletion test/gateway/anchor/get_state_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract('Anchor.getStateRoot()', function (accounts) {
await anchor.anchorStateRoot(
blockHeight,
stateRoot,
{from: worker},
{from: owner},
);

let latestStateRoot = await anchor.getStateRoot.call(blockHeight);
Expand Down

0 comments on commit 37870e6

Please sign in to comment.