-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #902 from keep-network/adding-relay-request-timeout
Sequencing relay requests In this PR we block upcoming requests from processing if there is one in progress. After a node generates a relay entry, then it can again start processing a new request.
- Loading branch information
Showing
5 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
contracts/solidity/test/TestKeepRandomBeaconOperatorRelayEntryTimeout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import expectThrowWithMessage from './helpers/expectThrowWithMessage'; | ||
import {bls} from './helpers/data'; | ||
import {initContracts} from './helpers/initContracts'; | ||
import mineBlocks from './helpers/mineBlocks'; | ||
|
||
contract('TestKeepRandomBeaconOperatorRelayEntryTimeout', function(accounts) { | ||
let operatorContract; | ||
const blocksForward = 20; | ||
const requestCounter = 0; | ||
|
||
describe("RelayRequestTimeout", function() { | ||
|
||
beforeEach(async () => { | ||
|
||
let contracts = await initContracts( | ||
accounts, | ||
artifacts.require('./KeepToken.sol'), | ||
artifacts.require('./StakingProxy.sol'), | ||
artifacts.require('./TokenStaking.sol'), | ||
artifacts.require('./KeepRandomBeaconServiceProxy.sol'), | ||
artifacts.require('./KeepRandomBeaconService.sol'), | ||
artifacts.require('./KeepRandomBeaconOperatorStub.sol') | ||
); | ||
|
||
operatorContract = contracts.operatorContract; | ||
|
||
// Using stub method to add first group to help testing. | ||
await operatorContract.registerNewGroup(bls.groupPubKey); | ||
// Passing a sender's authorization. accounts[0] is a msg.sender on blockchain | ||
await operatorContract.addServiceContract(accounts[0]) | ||
}); | ||
|
||
it("should not throw an error when sigining is in progress and the block number > relay entry timeout", async function() { | ||
await operatorContract.sign(requestCounter, bls.seed, bls.previousEntry); | ||
mineBlocks(blocksForward) | ||
await operatorContract.sign(requestCounter, bls.seed, bls.previousEntry); | ||
|
||
assert.equal((await operatorContract.getPastEvents())[0].event, 'SignatureRequested', "SignatureRequested event should occur on operator contract."); | ||
}) | ||
|
||
it("should throw an error when sigining is in progress and the block number <= relay entry timeout", async function() { | ||
await operatorContract.sign(requestCounter, bls.seed, bls.previousEntry); | ||
|
||
await expectThrowWithMessage(operatorContract.sign(requestCounter, bls.seed, bls.previousEntry), 'Relay entry is in progress.'); | ||
}) | ||
|
||
it("should not throw an error when sigining is not in progress and the block number > relay entry timeout", async function() { | ||
await operatorContract.sign(requestCounter, bls.seed, bls.previousEntry); | ||
|
||
assert.equal((await operatorContract.getPastEvents())[0].event, 'SignatureRequested', "SignatureRequested event should occur on operator contract."); | ||
}) | ||
|
||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default async (promise, message) => { | ||
try { | ||
await promise; | ||
} catch (error) { | ||
assert.include(error.message, message); | ||
|
||
return; | ||
} | ||
assert.fail('Expected throw not received'); | ||
}; |