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

feat(contracts-eth): don't allow zero-address initialization in AdminControlled #866

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/eth/nearbridge/contracts/AdminControlled.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ contract AdminControlled {
uint public paused;

constructor(address _admin, uint flags) {
verifyAdminAddress(_admin);
admin = _admin;
paused = flags;
}
Expand Down
25 changes: 17 additions & 8 deletions contracts/eth/nearbridge/test/NearBridge3.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('NearBridge with admin access', () => {
});

describe('AdminControlled', async () => {
it('Admin account matches', async() => {
it('Admin account matches', async () => {
expect(
await nearBridge.admin()
)
Expand All @@ -73,7 +73,7 @@ describe('NearBridge with admin access', () => {
.equal(adminAccount.address);
});

it('regular user can not perform admin functions', async() => {
it('regular user can not perform admin functions', async () => {
const recipientBalanceBefore = ethers.BigNumber.from(await ethers.provider.getBalance(userAccount2.address));
const contractBalanceBefore = ethers.BigNumber.from(await ethers.provider.getBalance(nearBridge.address));

Expand Down Expand Up @@ -261,6 +261,15 @@ describe('NearBridge with admin access', () => {
.revertedWith('Nominated admin shouldn\'t be zero address');
});

it('should not accept zero address as an admin in constructor', async () => {
await (await ethers.getContractFactory('AdminControlled')).deploy(
ethers.constants.AddressZero, // admin address
0, // paused flags
).then(() => { throw 'should not allow zero address for admin in constructor' })
.catch(() => {/* we are good */ })

});

it('should reject the nominated admin', async () => {
const newAdminAddress = '0x0123456789abcdefcafedeadbeefbea77a1de456';
await nearBridge.nominateAdmin(newAdminAddress);
Expand All @@ -285,8 +294,8 @@ describe('NearBridge with admin access', () => {

// Should now allow the current admin to accept the new admin
await expect(nearBridge
.connect(adminAccount)
.acceptAdmin())
.connect(adminAccount)
.acceptAdmin())
.to
.be
.revertedWith('Caller must be the nominated admin');
Expand All @@ -296,8 +305,8 @@ describe('NearBridge with admin access', () => {
const initialAdminAddress = await nearBridge.admin();
// Manually set the nominated admin to the same one
await nearBridge
.connect(adminAccount)
.adminSstore(1, initialAdminAddress);
.connect(adminAccount)
.adminSstore(1, initialAdminAddress);

// Verify that the nominated admin is indeed the same one (manually set)
expect(await nearBridge.nominatedAdmin())
Expand All @@ -314,8 +323,8 @@ describe('NearBridge with admin access', () => {
it('should not accept the zero address admin', async () => {
// Manually set the nominated admin to the same one
await nearBridge
.connect(adminAccount)
.adminSstore(1, ethers.constants.AddressZero);
.connect(adminAccount)
.adminSstore(1, ethers.constants.AddressZero);

// Verify that the nominated admin is indeed the zero address (manually set)
expect(await nearBridge.nominatedAdmin())
Expand Down