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

fix(protocol): fix occasional test failure #13173

Merged
merged 8 commits into from
Feb 17, 2023
Merged
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
80 changes: 31 additions & 49 deletions packages/protocol/test/L1/TaikoL1.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import { buildProposeBlockInputs } from "../utils/propose";
import Proposer from "../utils/proposer";
import { buildProveBlockInputs, proveBlock } from "../utils/prove";
import Prover from "../utils/prover";
import {
createAndSeedWallets,
seedTko,
sendTinyEtherToZeroAddress,
} from "../utils/seed";
import { seedTko, sendTinyEtherToZeroAddress } from "../utils/seed";
import {
commitProposeProveAndVerify,
sleepUntilBlockIsVerifiable,
Expand Down Expand Up @@ -188,57 +184,43 @@ describe("integration:TaikoL1", function () {
});

it("returns empty after a block is verified", async function () {
const provers = (await createAndSeedWallets(2, l1Signer)).map(
(p: ethersLib.Wallet) => new Prover(taikoL1, l2Provider, p)
);

await seedTko(provers, tkoTokenL1.connect(l1Signer));

l2Provider.on("block", blockListener(chan, genesisHeight));
await seedTko([prover], tkoTokenL1.connect(l1Signer));

const blockNumber = genesisHeight + 1;
/* eslint-disable-next-line */
for await (const blockNumber of chan) {
if (
blockNumber >
genesisHeight + config.maxNumBlocks.toNumber() - 1
) {
break;
}
const block = await l2Provider.getBlock(blockNumber);

const block = await l2Provider.getBlock(blockNumber);

// commit and propose block, so our provers can prove it.
const { proposedEvent } = await proposer.commitThenProposeBlock(
block
);
// commit and propose block, so our provers can prove it.
const { proposedEvent } = await proposer.commitThenProposeBlock(
block
);

await provers[0].prove(
proposedEvent.args.id.toNumber(),
blockNumber,
proposedEvent.args.meta as any as BlockMetadata
);
await prover.prove(
proposedEvent.args.id.toNumber(),
blockNumber,
proposedEvent.args.meta as any as BlockMetadata
);

let forkChoice = await taikoL1.getForkChoice(
proposedEvent.args.id.toNumber(),
block.parentHash
);
expect(forkChoice).not.to.be.undefined;
expect(forkChoice.provers.length).to.be.eq(1);
let forkChoice = await taikoL1.getForkChoice(
proposedEvent.args.id.toNumber(),
block.parentHash
);
expect(forkChoice).not.to.be.undefined;
expect(forkChoice.provers.length).to.be.eq(1);

await sleepUntilBlockIsVerifiable(
taikoL1,
proposedEvent.args.id.toNumber(),
0
);
const verifiedEvent = await verifyBlocks(taikoL1, 1);
expect(verifiedEvent).not.to.be.undefined;
await sleepUntilBlockIsVerifiable(
taikoL1,
proposedEvent.args.id.toNumber(),
0
);
const verifiedEvent = await verifyBlocks(taikoL1, 1);
expect(verifiedEvent).not.to.be.undefined;

forkChoice = await taikoL1.getForkChoice(
proposedEvent.args.id.toNumber(),
block.parentHash
);
expect(forkChoice.provers.length).to.be.eq(0);
}
forkChoice = await taikoL1.getForkChoice(
proposedEvent.args.id.toNumber(),
block.parentHash
);
expect(forkChoice.provers.length).to.be.eq(0);
});
});

Expand Down
88 changes: 37 additions & 51 deletions packages/protocol/test/tokenomics/proofReward.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,64 +225,50 @@ describe("tokenomics: proofReward", function () {

await seedTko(provers, tkoTokenL1.connect(l1Signer));

l2Provider.on("block", blockListener(chan, genesisHeight));
const blockNumber = genesisHeight + 1;

/* eslint-disable-next-line */
for await (const blockNumber of chan) {
if (
blockNumber >
genesisHeight + (config.maxNumBlocks.toNumber() - 1)
) {
break;
}
const block = await l2Provider.getBlock(blockNumber);

const block = await l2Provider.getBlock(blockNumber);
// commit and propose block, so our provers can prove it.
const { proposedEvent } = await proposer.commitThenProposeBlock(block);

// commit and propose block, so our provers can prove it.
const { proposedEvent } = await proposer.commitThenProposeBlock(
block
// submit a proof for each prover
for (const prover of provers) {
await prover.prove(
proposedEvent.args.id.toNumber(),
blockNumber,
proposedEvent.args.meta as any as BlockMetadata
);
}

// submit a proof for each prover
for (const prover of provers) {
await prover.prove(
proposedEvent.args.id.toNumber(),
blockNumber,
proposedEvent.args.meta as any as BlockMetadata
);
}
const forkChoice = await taikoL1.getForkChoice(
proposedEvent.args.id.toNumber(),
block.parentHash
);
expect(forkChoice).not.to.be.undefined;
expect(forkChoice.provers.length).to.be.eq(
config.maxProofsPerForkChoice.toNumber()
);

const forkChoice = await taikoL1.getForkChoice(
proposedEvent.args.id.toNumber(),
block.parentHash
);
expect(forkChoice).not.to.be.undefined;
expect(forkChoice.provers.length).to.be.eq(
config.maxProofsPerForkChoice.toNumber()
);
await sleepUntilBlockIsVerifiable(
taikoL1,
proposedEvent.args.id.toNumber(),
0
);
await verifyBlocks(taikoL1, 1);

// all provers had same initial TKO balance.
// each prover in order should have less balance than the previous.
for (let i = 0; i < forkChoice.provers.length; i++) {
if (i !== 0) {
const proverBalance = await tkoTokenL1.balanceOf(
forkChoice.provers[i]
);
const previousProverBalance = await tkoTokenL1.balanceOf(
forkChoice.provers[i - 1]
);

await sleepUntilBlockIsVerifiable(
taikoL1,
proposedEvent.args.id.toNumber(),
0
);
await verifyBlocks(taikoL1, 1);

// all provers had same initial TKO balance.
// each prover in order should have less balance than the previous.
for (let i = 0; i < forkChoice.provers.length; i++) {
if (i !== 0) {
const proverBalance = await tkoTokenL1.balanceOf(
forkChoice.provers[i]
);
const previousProverBalance = await tkoTokenL1.balanceOf(
forkChoice.provers[i - 1]
);

expect(previousProverBalance.gt(proverBalance)).to.be.eq(
true
);
}
expect(previousProverBalance.gt(proverBalance)).to.be.eq(true);
}
}
});
Expand Down