Skip to content

Commit

Permalink
Merge pull request #498 from EYBlockchain/westlad/unique-proposers
Browse files Browse the repository at this point in the history
bug - proposers can register twice
  • Loading branch information
ChaitanyaKonda authored Feb 18, 2022
2 parents 8a213cd + e6a9f3b commit 20bd374
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
1 change: 1 addition & 0 deletions nightfall-deployer/contracts/Proposers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ contract Proposers is Stateful, Structures, Config {
//add the proposer to the circular linked list
function registerProposer() external payable {
require(REGISTRATION_BOND <= msg.value, 'The registration payment is incorrect');
require(state.getProposer(msg.sender).thisAddress == address(0), 'This proposer is already registered');
payable(address(state)).transfer(REGISTRATION_BOND);
state.setBondAccount(msg.sender,REGISTRATION_BOND);
LinkedAddress memory currentProposer = state.getCurrentProposer();
Expand Down
52 changes: 39 additions & 13 deletions test/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,25 @@ describe('Testing the http API', () => {

describe('Basic Proposer tests', () => {
after(async () => {
// After the proposer tests, re-register proposers
const myAddress = (await getAccounts())[0];
const res = await chai
.request(optimistUrl)
.post('/proposer/register')
.send({ address: myAddress });
const { txDataToSign } = res.body;
expect(txDataToSign).to.be.a('string');
const bond = 10;
const count = logCounts.registerProposer;
await submitTransaction(txDataToSign, privateKey, proposersAddress, gas, bond);
await waitForTxExecution(count, 'registerProposer');
stateBalance += bond;
// After the proposer tests, re-register proposers, if needed
try {
const myAddress = (await getAccounts())[0];
const res = await chai
.request(optimistUrl)
.post('/proposer/register')
.send({ address: myAddress });
const { txDataToSign } = res.body;
expect(txDataToSign).to.be.a('string');
const bond = 10;
const count = logCounts.registerProposer;
await submitTransaction(txDataToSign, privateKey, proposersAddress, gas, bond);
await waitForTxExecution(count, 'registerProposer');
stateBalance += bond;
} catch (err) {
// an EVM revert almost certainly indicates that the proposer is already registered. That's
// fine, it's ok to continue
if (!err.message.includes('Transaction has been reverted by the EVM')) throw new Error(err);
}
});

it('should register a proposer', async () => {
Expand Down Expand Up @@ -306,6 +312,26 @@ describe('Testing the http API', () => {
});
});

it('should fail to register a proposer twice', async () => {
const myAddress = (await getAccounts())[0];
const res = await chai
.request(optimistUrl)
.post('/proposer/register')
.send({ address: myAddress });
const { txDataToSign } = res.body;
expect(txDataToSign).to.be.a('string');
// we have to pay 10 ETH to be registered
const bond = 10;
// now we need to sign the transaction and send it to the blockchain
console.log('submitting tx');
try {
await submitTransaction(txDataToSign, privateKey, proposersAddress, gas, bond);
expect.fail('Submitting the same proposer registration should have caused an EVM revert');
} catch (err) {
expect(err.message).to.include('Transaction has been reverted by the EVM');
}
});

it('should de-register a proposer', async () => {
const myAddress = (await getAccounts())[0];
const res = await chai.request(optimistUrl).post('/proposer/de-register');
Expand Down
13 changes: 9 additions & 4 deletions test/neg-http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,15 @@ describe('Testing the challenge http API', () => {
// should register a proposer
const myAddress = (await getAccounts())[0];
const bond = 10;
res = await chai.request(optimistUrl).post('/proposer/register').send({ address: myAddress });
txToSign = res.body.txDataToSign;
await submitTransaction(txToSign, privateKey, proposersAddress, gas, bond);

try {
res = await chai.request(optimistUrl).post('/proposer/register').send({ address: myAddress });
txToSign = res.body.txDataToSign;
await submitTransaction(txToSign, privateKey, proposersAddress, gas, bond);
} catch (err) {
// an EVM revert almost certainly indicates that the proposer is already registered. That's
// fine, it's ok to continue
if (!err.message.includes('Transaction has been reverted by the EVM')) throw new Error(err);
}
// should subscribe to block proposed event with the provided incoming viewing key
await chai
.request(url)
Expand Down

0 comments on commit 20bd374

Please sign in to comment.