-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NearProver:add scripts&tests for bridge upgradability (#647)
* NearProver:add scripts&tests for bridge upgradability * NearProver: wait receipt for 10 blocks on upgrade * Add ledger support * Apply eslint fixes and add a command to Makefile * Update contracts/eth/nearprover/UPGRADE.md * Change CLI line endings * NearBridge: use local `utils` package * Update yarn.lock files * NearBridge: update tests `utils` package reference * NearBridge: add tests for admin upgradability. * NearBridge: hardhat config allow using empty PK. * NearBridge: add scripts to upgrade an admin. Co-authored-by: Marcelo Fornet <[email protected]> Co-authored-by: Karim <[email protected]> Co-authored-by: Karim <[email protected]>
- Loading branch information
1 parent
1a473b7
commit fb38f59
Showing
19 changed files
with
3,346 additions
and
3,073 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.env | ||
node_modules | ||
artifacts | ||
cache | ||
coverage | ||
|
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
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
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 |
---|---|---|
@@ -1,27 +1,77 @@ | ||
const { ethers } = require('hardhat'); | ||
const { expect } = require('chai'); | ||
|
||
const { borshify, borshifyInitialValidators } = require('rainbow-bridge-lib/rainbow/borsh') | ||
|
||
let Ed25519, NearBridge; | ||
|
||
beforeEach(async function () { | ||
Ed25519 = await (await ethers.getContractFactory('Ed25519')).deploy(); | ||
NearBridge = await (await ethers.getContractFactory('NearBridge')).deploy( | ||
Ed25519.address, | ||
ethers.BigNumber.from("1000000000000000000"), // 1e18 | ||
ethers.BigNumber.from("10"), // lock duration | ||
ethers.BigNumber.from("20000000000"), // replace duration | ||
await (await ethers.getSigners())[0].getAddress(), | ||
0 | ||
); | ||
await NearBridge.deposit({ value: ethers.utils.parseEther('1') }); | ||
}); | ||
const { borshify, borshifyInitialValidators } = require('rainbow-bridge-utils') | ||
|
||
|
||
describe('New tests', () => { | ||
let Ed25519; | ||
let NearBridge; | ||
let AdminWallet; | ||
|
||
beforeEach(async function () { | ||
Ed25519 = await (await ethers.getContractFactory('Ed25519')).deploy(); | ||
[AdminWallet] = await ethers.getSigners(); | ||
NearBridge = await (await ethers.getContractFactory('NearBridge')).deploy( | ||
Ed25519.address, | ||
ethers.BigNumber.from("1000000000000000000"), // 1e18 | ||
ethers.BigNumber.from("10"), // lock duration | ||
ethers.BigNumber.from("20000000000"), // replace duration | ||
await AdminWallet.getAddress(), | ||
0 | ||
); | ||
await NearBridge.deposit({ value: ethers.utils.parseEther('1') }); | ||
}); | ||
|
||
it('Verify init with validators V1', async function () { | ||
const initialValidators = borshifyInitialValidators(require('./block_validators_v1_testnet.json').next_bps); | ||
console.log(`Initial validators: ${initialValidators.toString('hex')}`); | ||
it('Verify init with validators V1', async function () { | ||
const initialValidators = borshifyInitialValidators(require('./block_validators_v1_testnet.json').next_bps); | ||
|
||
expect(await NearBridge.initWithValidators(borshifyInitialValidators(require('./block_validators_v1_testnet.json').next_bps))); | ||
expect(await NearBridge.initWithValidators(borshifyInitialValidators(require('./block_validators_v1_testnet.json').next_bps))); | ||
}); | ||
}); | ||
|
||
|
||
describe('NearBridge with admin access', () => { | ||
const ADMIN_ADDRESS_SLOT = 0; | ||
let nearBridge; | ||
let adminAccount; | ||
|
||
beforeEach(async () => { | ||
ed25519 = await (await ethers.getContractFactory('Ed25519')).deploy(); | ||
[deployerAccount] = await ethers.getSigners(); | ||
|
||
// Make the deployer admin | ||
adminAccount = deployerAccount; | ||
|
||
nearBridge = await (await ethers.getContractFactory('NearBridge')).deploy( | ||
ed25519.address, | ||
ethers.BigNumber.from("1000000000000000000"), // 1e18 | ||
ethers.BigNumber.from("10"), // lock duration | ||
ethers.BigNumber.from("20000000000"), // replace duration | ||
await adminAccount.getAddress(), | ||
0 | ||
); | ||
}); | ||
|
||
describe('Upgradability', async () => { | ||
it('should upgrade the admin address from the provided hex string', async () => { | ||
const initialAdminAddress = await nearBridge.admin(); | ||
expect(initialAdminAddress) | ||
.to | ||
.equal(await adminAccount.address); | ||
|
||
const newAdminAddress = '0x0123456789abcdefcafedeadbeefbea77a1de456'; | ||
expect(newAdminAddress) | ||
.not | ||
.equal(initialAdminAddress); | ||
|
||
// Mask matches only on the latest 20 bytes (to store the address) | ||
const mask = ethers.BigNumber.from("0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff"); | ||
nearBridge.adminSstoreWithMask(ADMIN_ADDRESS_SLOT, newAdminAddress, mask); | ||
|
||
expect((await nearBridge.admin()).toLowerCase()) | ||
.to | ||
.equal(newAdminAddress); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.