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(tests): cleanup tests to prepare for tokenomics testing #11316

Merged
merged 49 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b67e080
cleanup TaikoL1 tests with refactored code to utils folders before at…
cyberhorsey Jan 6, 2023
777179f
separate bridge and bridge integration tests, move deployBridge
cyberhorsey Jan 6, 2023
3beee08
additional bridge test refactoring
cyberhorsey Jan 6, 2023
931e1ef
move ethervault/tokenvautl to own folders, addtl refactors from task/…
cyberhorsey Jan 6, 2023
7fd5c31
folder names match contract names
cyberhorsey Jan 6, 2023
4c0aab4
undo folder structure, should match contracts tree imo
cyberhorsey Jan 6, 2023
377324e
Update TkoToken.test.ts
dantaik Jan 7, 2023
47beee7
Merge branch 'main' into test_cleanup
cyberhorsey Jan 9, 2023
be41408
check status/receipt
cyberhorsey Jan 9, 2023
751492c
wip
cyberhorsey Jan 10, 2023
e2be1a0
merge main
cyberhorsey Jan 10, 2023
ad60e97
Merge branch 'test_cleanup' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 10, 2023
e9e210b
merge main
cyberhorsey Jan 10, 2023
47e88eb
merge main, tests passing
cyberhorsey Jan 10, 2023
1c8a532
chmod test tokenomics
cyberhorsey Jan 10, 2023
e701ac5
Update packages/protocol/test/L1/TaikoL1.integration.test.ts
cyberhorsey Jan 10, 2023
cbdc1fa
some refactors for reusabel deploy functions, beginning of tokenomcis…
cyberhorsey Jan 12, 2023
c7a3edc
Merge branch 'test_cleanup' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 12, 2023
0ace5d2
Merge branch 'main' into test_cleanup
cyberhorsey Jan 12, 2023
f980093
add test assertions on block prosal for reward and fees
cyberhorsey Jan 12, 2023
dbeb9e5
expect doesnt work in the event listener
cyberhorsey Jan 12, 2023
c989190
refactor to an onNewL2Block
cyberhorsey Jan 12, 2023
1555436
Merge branch 'test_cleanup' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 13, 2023
a388095
tests for bootstrap halving
cyberhorsey Jan 13, 2023
c6ee1ef
bridge test cleanup more
cyberhorsey Jan 13, 2023
44a0705
block max gas limit usage in test
cyberhorsey Jan 13, 2023
b9ae690
remove prover
cyberhorsey Jan 13, 2023
7010a24
comment out prove test.
cyberhorsey Jan 13, 2023
074b5bd
use automine
cyberhorsey Jan 13, 2023
822a725
add todo
cyberhorsey Jan 13, 2023
539c6df
remove 0 check
cyberhorsey Jan 13, 2023
7735570
resolve test issue?
cyberhorsey Jan 13, 2023
2cc7b03
Update packages/protocol/test/L1/TaikoL1.integration.test.ts
cyberhorsey Jan 13, 2023
4298830
addressManager utils functions, l1/l2 provider, l2signer
cyberhorsey Jan 13, 2023
71eec5d
Merge branch 'test_cleanup' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 13, 2023
afdbe9c
set taikoL2 on taikoL1
cyberhorsey Jan 13, 2023
97fbb70
set taiko
cyberhorsey Jan 13, 2023
7efe07e
Merge branch 'main' into test_cleanup
cyberhorsey Jan 13, 2023
2627e97
put tokenomics utils functions in own file
cyberhorsey Jan 13, 2023
7aa50b1
Merge branch 'test_cleanup' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 13, 2023
0e71695
dont need prove tests yet
cyberhorsey Jan 13, 2023
c142873
testtaikoL2
cyberhorsey Jan 14, 2023
81d671b
WIP on proving, anchoring
cyberhorsey Jan 14, 2023
9e24c88
await sendtx
cyberhorsey Jan 14, 2023
18801d6
taikol2 test contracts
cyberhorsey Jan 14, 2023
471f871
contract type
cyberhorsey Jan 14, 2023
65697ba
disable public inputs
cyberhorsey Jan 14, 2023
b1358dd
wip cleanup
cyberhorsey Jan 14, 2023
34ff709
Update TaikoL2.sol
dantaik Jan 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: MIT
//
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import {IProofVerifier} from "../../L1/ProofVerifier.sol";
import "../../L1/TaikoL1.sol";

contract TestTaikoL1EnableTokenomics is TaikoL1, IProofVerifier {
function getConfig()
public
pure
override
returns (TaikoData.Config memory config)
{
config.chainId = 167;
// up to 2048 pending blocks
config.maxNumBlocks = 4;
config.blockHashHistory = 3;
// This number is calculated from maxNumBlocks to make
// the 'the maximum value of the multiplier' close to 20.0
config.zkProofsPerBlock = 1;
config.maxVerificationsPerTx = 2;
config.commitConfirmations = 1;
config.maxProofsPerForkChoice = 5;
config.blockMaxGasLimit = 30000000; // TODO
config.maxTransactionsPerBlock = 20; // TODO
config.maxBytesPerTxList = 10240; // TODO
config.minTxGasLimit = 21000; // TODO
config.anchorTxGasLimit = 250000;
config.feePremiumLamda = 590;
config.rewardBurnBips = 100; // 100 basis points or 1%
config.proposerDepositPctg = 25; // 25%

// Moving average factors
config.feeBaseMAF = 1024;
config.blockTimeMAF = 64;
config.proofTimeMAF = 64;

config.rewardMultiplierPctg = 400; // 400%
config.feeGracePeriodPctg = 125; // 125%
config.feeMaxPeriodPctg = 375; // 375%
config.blockTimeCap = 48 seconds;
config.proofTimeCap = 60 minutes;
config.boostrapDiscountHalvingPeriod = 180 days;
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
}

function verifyZKP(
bytes memory /*verificationKey*/,
bytes calldata /*zkproof*/,
bytes32 /*blockHash*/,
address /*prover*/,
bytes32 /*txListHash*/
) public pure override returns (bool) {
return true;
}

function verifyMKP(
bytes memory /*key*/,
bytes memory /*value*/,
bytes memory /*proof*/,
bytes32 /*root*/
) public pure override returns (bool) {
return true;
}
}
91 changes: 0 additions & 91 deletions packages/protocol/tasks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as fs from "fs";
import * as log from "./log";
import { Block, BlockHeader, EthGetProofResponse } from "../test/utils/rpc";
import RLP from "rlp";

async function deployContract(
hre: any,
Expand Down Expand Up @@ -68,105 +66,16 @@ function getDeployments(_fileName: string) {
return JSON.parse(`${json}`);
}

async function getMessageStatusSlot(hre: any, signal: any) {
return hre.ethers.utils.solidityKeccak256(
["string", "bytes"],
["MESSAGE_STATUS", signal]
);
}

async function decode(hre: any, type: any, data: any) {
return hre.ethers.utils.defaultAbiCoder.decode([type], data).toString();
}

function getSignalSlot(hre: any, sender: any, signal: any) {
return hre.ethers.utils.keccak256(
hre.ethers.utils.solidityPack(
["string", "address", "bytes32"],
["SIGNAL", sender, signal]
)
);
}

const MessageStatus = {
NEW: 0,
RETRIABLE: 1,
DONE: 2,
FAILED: 3,
};

async function getLatestBlockHeader(hre: any) {
const block: Block = await hre.ethers.provider.send(
"eth_getBlockByNumber",
["latest", false]
);

const logsBloom = block.logsBloom.toString().substring(2);

const blockHeader: BlockHeader = {
parentHash: block.parentHash,
ommersHash: block.sha3Uncles,
beneficiary: block.miner,
stateRoot: block.stateRoot,
transactionsRoot: block.transactionsRoot,
receiptsRoot: block.receiptsRoot,
logsBloom: logsBloom.match(/.{1,64}/g)!.map((s: string) => "0x" + s),
difficulty: block.difficulty,
height: block.number,
gasLimit: block.gasLimit,
gasUsed: block.gasUsed,
timestamp: block.timestamp,
extraData: block.extraData,
mixHash: block.mixHash,
nonce: block.nonce,
baseFeePerGas: block.baseFeePerGas ? parseInt(block.baseFeePerGas) : 0,
};

return { block, blockHeader };
}

async function getSignalProof(
hre: any,
contractAddress: string,
key: string,
blockNumber: number,
blockHeader: BlockHeader
) {
const proof: EthGetProofResponse = await hre.ethers.provider.send(
"eth_getProof",
[contractAddress, [key], blockNumber]
);

// RLP encode the proof together for LibTrieProof to decode
const encodedProof = hre.ethers.utils.defaultAbiCoder.encode(
["bytes", "bytes"],
[
RLP.encode(proof.accountProof),
RLP.encode(proof.storageProof[0].proof),
]
);
// encode the SignalProof struct from LibBridgeSignal
const signalProof = hre.ethers.utils.defaultAbiCoder.encode(
[
"tuple(tuple(bytes32 parentHash, bytes32 ommersHash, address beneficiary, bytes32 stateRoot, bytes32 transactionsRoot, bytes32 receiptsRoot, bytes32[8] logsBloom, uint256 difficulty, uint128 height, uint64 gasLimit, uint64 gasUsed, uint64 timestamp, bytes extraData, bytes32 mixHash, uint64 nonce, uint256 baseFeePerGas) header, bytes proof)",
],
[{ header: blockHeader, proof: encodedProof }]
);

return signalProof;
}

export {
deployContract,
getDeployer,
waitTx,
getContract,
saveDeployments,
getDeployments,
getMessageStatusSlot,
getSignalSlot,
decode,
MessageStatus,
getLatestBlockHeader,
getSignalProof,
};
160 changes: 160 additions & 0 deletions packages/protocol/test/L1/TaikoL1.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { expect } from "chai";
import { BigNumber, ethers as ethersLib } from "ethers";
import { ethers } from "hardhat";
import { TaikoL1, TaikoL2 } from "../../typechain";
import { BlockMetadata } from "../utils/block_metadata";
import { commitBlock, generateCommitHash } from "../utils/commit";
import { buildProposeBlockInputs, proposeBlock } from "../utils/propose";
import { deployTaikoL1 } from "../utils/taikoL1";
import { deployTaikoL2 } from "../utils/taikoL2";

describe("integration:TaikoL1", function () {
let taikoL1: TaikoL1;
let taikoL2: TaikoL2;
let l2Provider: ethersLib.providers.JsonRpcProvider;
let l2Signer: ethersLib.Signer;

beforeEach(async function () {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
l2Provider = new ethers.providers.JsonRpcProvider(
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
"http://localhost:28545"
);

l2Signer = await l2Provider.getSigner(
(
await l2Provider.listAccounts()
)[0]
);

taikoL2 = await deployTaikoL2(l2Signer);
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved

const genesisHash = taikoL2.deployTransaction.blockHash as string;

taikoL1 = await deployTaikoL1(genesisHash);
});

describe("isCommitValid()", async function () {
it("should not be valid", async function () {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
const block = await l2Provider.getBlock("latest");
const commit = generateCommitHash(block);

const isCommitValid = await taikoL1.isCommitValid(
1,
1,
commit.hash
);

expect(isCommitValid).to.be.eq(false);
});
});

describe("getProposedBlock()", function () {
it("proposed block does not exist", async function () {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
const block = await taikoL1.getProposedBlock(123);
expect(block[0]).to.be.eq(ethers.constants.HashZero);
expect(block[1]).to.be.eq(ethers.constants.AddressZero);
expect(block[2]).to.be.eq(BigNumber.from(0));
});
});
describe("commitBlock() -> proposeBlock() integration", async function () {
it("should revert with invalid meta", async function () {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
const block = await l2Provider.getBlock("latest");
const { tx, commit } = await commitBlock(taikoL1, block);

await expect(
proposeBlock(
taikoL1,
block,
commit.txListHash,
tx.blockNumber as number,
1,
block.gasLimit
)
).to.be.revertedWith("L1:placeholder");
});

it("should revert with invalid gasLimit", async function () {
const block = await l2Provider.getBlock("latest");
const { tx, commit } = await commitBlock(taikoL1, block);

// blockMetadata is inputs[0], txListBytes = inputs[1]
const config = await taikoL1.getConfig();
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
const gasLimit = config[7];
await proposeBlock(
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
taikoL1,
block,
commit.txListHash,
tx.blockNumber as number,
0,
block.gasLimit
);

await expect(
proposeBlock(
taikoL1,
block,
commit.txListHash,
tx.blockNumber as number,
0,
gasLimit.add(1)
)
).to.be.revertedWith("L1:gasLimit");
});

it("should revert with invalid extraData", async function () {
const block = await l2Provider.getBlock("latest");
const { tx, commit } = await commitBlock(taikoL1, block);

const meta: BlockMetadata = {
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
id: 0,
l1Height: 0,
l1Hash: ethers.constants.HashZero,
beneficiary: block.miner,
txListHash: commit.txListHash,
mixHash: ethers.constants.HashZero,
extraData: ethers.utils.hexlify(ethers.utils.randomBytes(33)), // invalid extradata
gasLimit: block.gasLimit,
timestamp: 0,
commitSlot: 1,
commitHeight: tx.blockNumber as number,
};

const inputs = buildProposeBlockInputs(block, meta);

await expect(taikoL1.proposeBlock(inputs)).to.be.revertedWith(
"L1:extraData"
);
});

it("should commit and be able to propose", async function () {
const block = await l2Provider.getBlock("latest");
const { tx, commit } = await commitBlock(taikoL1, block);

await proposeBlock(
taikoL1,
block,
commit.txListHash,
tx.blockNumber as number,
0,
block.gasLimit
);

const stateVariables = await taikoL1.getStateVariables();
const nextBlockId = stateVariables[4];
const proposedBlock = await taikoL1.getProposedBlock(
nextBlockId.sub(1)
);

expect(proposedBlock[0]).not.to.be.eq(ethers.constants.HashZero);
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
expect(proposedBlock[2]).not.to.be.eq(ethers.constants.AddressZero);
expect(proposedBlock[3]).not.to.be.eq(BigNumber.from(0));

const isCommitValid = await taikoL1.isCommitValid(
1,
tx.blockNumber as number,
commit.hash
);

expect(isCommitValid).to.be.eq(true);
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
});
});
});