Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only organization should anchor state roots #560

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