Skip to content

Commit

Permalink
fixed nearbridge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
UrAvgDeveloper committed May 12, 2023
1 parent 011ca51 commit eeb19aa
Show file tree
Hide file tree
Showing 22 changed files with 6,294 additions and 411 deletions.
375 changes: 375 additions & 0 deletions contracts/eth/nearbridge/test/126313429.json

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions contracts/eth/nearbridge/test/126315547.json

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions contracts/eth/nearbridge/test/126315744.json

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions contracts/eth/nearbridge/test/126315811.json

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions contracts/eth/nearbridge/test/126315892.json

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions contracts/eth/nearbridge/test/126315927.json

Large diffs are not rendered by default.

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.

35 changes: 16 additions & 19 deletions contracts/eth/nearbridge/test/NearBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,32 @@ 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',
);
});

Expand Down
93 changes: 43 additions & 50 deletions contracts/eth/nearbridge/test/NearBridge2.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,20 @@ 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 () {
Expand Down Expand Up @@ -87,68 +84,64 @@ 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('./126313429.json');
const block126315547 = require('./126315547.json');
const block126315744 = require('./126315744.json');
const block126315811 = require('./126315811.json');
const block126315892 = require('./126315892.json');
const block126315927 = require('./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('./126313429.json');
const block126315547 = require('./126315547.json');
const block126315744 = require('./126315744.json');
const block126315811 = require('./126315811.json');
const block126315892 = require('./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
25 changes: 0 additions & 25 deletions contracts/eth/nearbridge/test/block_120998.json

This file was deleted.

25 changes: 0 additions & 25 deletions contracts/eth/nearbridge/test/block_121498.json

This file was deleted.

25 changes: 0 additions & 25 deletions contracts/eth/nearbridge/test/block_121998.json

This file was deleted.

Loading

0 comments on commit eeb19aa

Please sign in to comment.