Skip to content

Commit

Permalink
Merge branch 'master' into eth2-client-0.3.1-trusted-signer
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Oct 24, 2023
2 parents b0fee41 + 3420dc7 commit 4442fe4
Show file tree
Hide file tree
Showing 94 changed files with 17,516 additions and 986 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
name: E2E tests
jobs:
test:
runs-on: self-hosted
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -30,8 +30,10 @@ jobs:

name: ${{ matrix.job-name }}
steps:
- name: Install LFS
run: apt-get install git-lfs
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "16.x"

- name: Clone the repository
uses: actions/checkout@v3
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ coverage
coverage.json
node_modules
target
testdata
vendor
.history
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/
* @sept-en @karim-en
* @karim-en
14 changes: 13 additions & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const {
} = require('rainbow-bridge-testing')
const { ETHDump } = require('./commands/eth-dump')
const { NearDump } = require('./commands/near-dump')
const { ethToNearFindProof } = require('rainbow-bridge-eth2near-block-relay')
const { ethToNearFindProof, ethToNearFindStorageProof } = require('rainbow-bridge-eth2near-block-relay')
const { RainbowConfig } = require('rainbow-bridge-utils')
const { UpdateDagMerkleRoots } = require('./commands/update-dag-merkle-roots')
const {
Expand Down Expand Up @@ -649,6 +649,18 @@ RainbowConfig.addOptions(
]
)

RainbowConfig.addOptions(
program
.command('eth-to-near-find-storage-proof <contract-address> <storage_key> <block-number>')
.description('Get eth-to-near storage proof for provided storage key.'),
async (contractAddress, storageKey, blockNumber, args) => {
await ethToNearFindStorageProof({ contractAddress, storageKey, blockNumber, ...args })
},
[
'eth-node-url'
]
)

// Testing commands
const testingCommand = program
.command('TESTING')
Expand Down
5 changes: 0 additions & 5 deletions contracts/eth/ci/test_verify_near_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ set -euo pipefail
CI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR=$CI_DIR/..

mkdir -p $ROOT_DIR/testdata
cd $ROOT_DIR/testdata
curl https://s3-us-west-1.amazonaws.com/rainbow-bridge.nearprotocol.com/test-data/near-headers.tar.gz -o near-headers.tar.gz
tar zxf near-headers.tar.gz

cd $ROOT_DIR
yarn

Expand Down
5 changes: 0 additions & 5 deletions contracts/eth/ci/test_verify_near_proofs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ set -euo pipefail
CI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR=$CI_DIR/..

mkdir -p $ROOT_DIR/testdata
cd $ROOT_DIR/testdata
curl https://s3-us-west-1.amazonaws.com/rainbow-bridge.nearprotocol.com/test-data/near-proofs.tar.gz -o near-proofs.tar.gz
tar zxf near-proofs.tar.gz

cd $ROOT_DIR
yarn

Expand Down
2 changes: 2 additions & 0 deletions contracts/eth/nearbridge/.catalog-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
system: bridge-protocol
deployedAt:
- contract:ethereum/mainnet/0x88f975d5a1153ea92af66e7c4292576a329c04b6
- contract:ethereum/goerli/0x6f2C9EbFB1e3Ff065E6725A715B458EF13206097
interactsWith: []
---
apiVersion: backstage.io/v1alpha1
Expand All @@ -43,6 +44,7 @@ spec:
system: bridge-protocol
deployedAt:
- contract:ethereum/mainnet/0x3FEFc5A4B1c02f21cBc8D3613643ba0635b9a873
- contract:ethereum/goerli/0x37c2d89b55bfd95532637554711441017efabfef
interactsWith:
- relayer:ethereum/mainnet/0x015e634c7c1311a9034220c28d3d12b7f710a3b1
deprecated:
Expand Down
44 changes: 0 additions & 44 deletions contracts/eth/nearbridge/test/181.json

This file was deleted.

38 changes: 0 additions & 38 deletions contracts/eth/nearbridge/test/368.json

This file was deleted.

1 change: 0 additions & 1 deletion contracts/eth/nearbridge/test/369.json

This file was deleted.

37 changes: 16 additions & 21 deletions contracts/eth/nearbridge/test/NearBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,37 @@ beforeEach(async function () {
});

it('should be ok', async function () {
// Skip until tests are upgraded having blocks after nearcore 1.23.0
this.skip();
const block91425093 = borshify(require('./block_91425093.json'));
const block91468293 = borshify(require('./block_91468293.json'));
const block91511493 = borshify(require('./block_91511493.json'));

const block120998 = borshify(require('./block_120998.json'));
const block121498 = borshify(require('./block_121498.json'));
const block121998 = borshify(require('./block_121998.json'));

// We should use previous epoch's next_bps to initWithBlock with block_120998, but they happens to be same
await NearBridge.initWithValidators(borshifyInitialValidators(require('./block_120998.json').next_bps));
await NearBridge.initWithBlock(block120998);
expect(await NearBridge.blockHashes(120998)).to.be.equal(
'0x1a7a07b5eee1f4d8d7e47864d533143972f858464bacdc698774d167fb1b40e6',
// We should use previous epoch's next_bps to initWithBlock with block_91425093, but they happens to be same
await NearBridge.initWithValidators(borshifyInitialValidators(require('./block_91425093.json').next_bps));
await NearBridge.initWithBlock(block91425093);
expect(await NearBridge.blockHashes(91425093)).to.be.equal(
'0x25d3099add104e19078cc02f5e13eff79386cdde07a841b59d9a078e1f8e6384',
);

await NearBridge.addLightClientBlock(block121498);
await NearBridge.addLightClientBlock(block91468293);
expect(await NearBridge.checkBlockProducerSignatureInHead(0)).to.be.true;

await expect(NearBridge.addLightClientBlock(block121998)).to.be.revertedWith('Epoch id of the block is not valid');
await expect(NearBridge.addLightClientBlock(block91511493)).to.be.revertedWith('Epoch id of the block is not valid');
await increaseTime(3600);
expect(await NearBridge.blockHashes(121498)).to.be.equal(
'0x508307e7af9bdbb297afa7af0541130eb32f0f028151319f5a4f7ae68b0ecc56',
expect(await NearBridge.blockHashes(91468293)).to.be.equal(
'0xee41bd80c7f770caefb4788876e1c027871e42a333d6aabf894a6ce38ade8d33',
);

await NearBridge.addLightClientBlock(block121998);
expect(await NearBridge.checkBlockProducerSignatureInHead(0)).to.be.true;
await NearBridge.addLightClientBlock(block91511493);
expect(await NearBridge.checkBlockProducerSignatureInHead(1)).to.be.true;

await increaseTime(3600);
expect(await NearBridge.blockHashes(121998)).to.be.equal(
'0x2358c4881bbd111d2e4352b6a7e6c7595fb39d3c9897d3c624006be1ef809abf',
expect(await NearBridge.blockHashes(91511493)).to.be.equal(
'0x0552d0022ce2a9c83d96f11126090c9fe6b866198be715228f95ad700d8fb19c',
);
});

if (process.env.NEAR_HEADERS_DIR) {
it('ok with many block headers', async function () {
// Skip until tests are upgraded having blocks after nearcore 1.23.0
this.skip();

this.timeout(0);
const blockFiles = await fs.readdir(process.env.NEAR_HEADERS_DIR);
Expand Down
100 changes: 46 additions & 54 deletions contracts/eth/nearbridge/test/NearBridge2.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,29 @@ it('should be ok', async function () {

});

it('2020-09-09 Example', async function () {
// Skip until tests are upgraded having blocks after nearcore 1.23.0
this.skip();

const block_15178713 = borshify(require('./block_15178713.json'));
const block_15178760 = borshify(require('./block_15178760.json'));
const block_15204402 = borshify(require('./block_15204402.json'));
const block_15248583 = borshify(require('./block_15248583.json'));

await NearBridge.initWithValidators(borshifyInitialValidators(require('./init_validators_15178713.json')));
await NearBridge.initWithBlock(block_15178713);
it('2023-05-09 Example', async function () {
const block_91425093 = borshify(require('./block_91425093.json'));
const block_91468293 = borshify(require('./block_91468293.json'));
const block_91511493 = borshify(require('./block_91511493.json'));
const block_91522568 = borshify(require('./block_91522568.json'));

await NearBridge.initWithValidators(borshifyInitialValidators(require('./init_validators_91425093.json')));
await NearBridge.initWithBlock(block_91425093);
await increaseTime(3600);
await NearBridge.addLightClientBlock(block_15178760);
await NearBridge.addLightClientBlock(block_91468293);
await increaseTime(3600);
await NearBridge.addLightClientBlock(block_15204402);
await NearBridge.addLightClientBlock(block_91511493);
await increaseTime(3600);
await NearBridge.addLightClientBlock(block_15248583);
await NearBridge.addLightClientBlock(block_91522568);
});

it('Add second block in first epoch should be verifiable', async function () {
// Get "initial validators" that will produce block 304
const block244 = require('./244.json');
const block244 = require('./block_244.json');
const initialValidators = block244.next_bps;

const block304 = require('./304.json');
const block308 = require('./308.json');
const block304 = require('./block_304.json');
const block308 = require('./block_308.json');

await NearBridge.initWithValidators(borshifyInitialValidators(initialValidators));
await NearBridge.initWithBlock(borshify(block304));
Expand All @@ -87,68 +84,63 @@ it('Add second block in first epoch should be verifiable', async function () {
});

it('Test adding blocks in new epoch when bps change', async function () {
// Skip until tests are upgraded having blocks after nearcore 1.23.0
this.skip();

const block181 = require('./181.json');
const block244 = require('./244.json');
const block304 = require('./304.json');
const block308 = require('./308.json');
const block368 = require('./368.json');
const block369 = require('./369.json');
const block126313429 = require('./block_126313429.json');
const block126315547 = require('./block_126315547.json');
const block126315744 = require('./block_126315744.json');
const block126315811 = require('./block_126315811.json');
const block126315892 = require('./block_126315892.json');
const block126315927 = require('./block_126315927.json');

await NearBridge.initWithValidators(borshifyInitialValidators(block181.next_bps));
await NearBridge.initWithBlock(borshify(block244));
await NearBridge.blockHashes(244);
await NearBridge.initWithValidators(borshifyInitialValidators(block126313429.next_bps));
await NearBridge.initWithBlock(borshify(block126315547));
await NearBridge.blockHashes(126315547);

await increaseTime(3600);

await NearBridge.addLightClientBlock(borshify(block304));
await NearBridge.blockHashes(304);
await NearBridge.addLightClientBlock(borshify(block126315744));
await NearBridge.blockHashes(126315744);

await increaseTime(3600);

await NearBridge.addLightClientBlock(borshify(block308));
await NearBridge.blockHashes(308);
await NearBridge.addLightClientBlock(borshify(block126315811));
await NearBridge.blockHashes(126315811);

await increaseTime(3600);

await NearBridge.addLightClientBlock(borshify(block368));
await NearBridge.blockHashes(368);
await NearBridge.addLightClientBlock(borshify(block126315892));
await NearBridge.blockHashes(126315892);

await increaseTime(3600);

await NearBridge.addLightClientBlock(borshify(block369));
await NearBridge.blockHashes(369);
await NearBridge.addLightClientBlock(borshify(block126315927));
await NearBridge.blockHashes(126315927);
});

it('After challenge prev should be revert to prev epoch of latest valid block', async function () {
// Skip until tests are upgraded having blocks after nearcore 1.23.0
this.skip();

const block181 = require('./181.json');
const block244 = require('./244.json');
const block304 = require('./304.json');
const block308 = require('./308.json');
const block368 = require('./368.json');
const block126313429 = require('./block_126313429.json');
const block126315547 = require('./block_126315547.json');
const block126315744 = require('./block_126315744.json');
const block126315811 = require('./block_126315811.json');
const block126315892 = require('./block_126315892.json');

await NearBridge.initWithValidators(borshifyInitialValidators(block181.next_bps));
await NearBridge.initWithBlock(borshify(block244));
await NearBridge.blockHashes(244);
await NearBridge.initWithValidators(borshifyInitialValidators(block126313429.next_bps));
await NearBridge.initWithBlock(borshify(block126315547));
await NearBridge.blockHashes(126315547);

await increaseTime(3600);
await NearBridge.addLightClientBlock(borshify(block304));
await NearBridge.blockHashes(304);
await NearBridge.addLightClientBlock(borshify(block126315744));
await NearBridge.blockHashes(126315744);

await increaseTime(3600);
await NearBridge.addLightClientBlock(borshify(block308));
await NearBridge.blockHashes(308);
await NearBridge.addLightClientBlock(borshify(block126315811));
await NearBridge.blockHashes(126315811);

await increaseTime(3600);

block368.approvals_after_next[0] = block368.approvals_after_next[1];
await NearBridge.addLightClientBlock(borshify(block368));
await NearBridge.blockHashes(368);
block126315892.approvals_after_next[0] = block126315892.approvals_after_next[1];
await NearBridge.addLightClientBlock(borshify(block126315892));
await NearBridge.blockHashes(126315892);
expect((await NearBridge.lastValidAt())).to.not.be.equal(0);

await NearBridge.challenge(ethers.constants.AddressZero, 0)
Expand Down
Loading

0 comments on commit 4442fe4

Please sign in to comment.