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(test): making tests type-safe #318

Merged
merged 26 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
791f33b
making fixtures type-safe
RogerLamTd Nov 22, 2022
a6720e3
Merge branch 'main' into testcleanup
RogerLamTd Nov 22, 2022
854deec
linting
RogerLamTd Nov 22, 2022
f44f86c
fix libsend tests
RogerLamTd Nov 22, 2022
ec70788
Merge branch 'main' into testcleanup
cyberhorsey Nov 23, 2022
2552093
added missing test case LibBridgeRetry
RogerLamTd Nov 24, 2022
1496808
retryMessage tests attempt
RogerLamTd Nov 26, 2022
1d32e2d
Merge branch 'main' into testcleanup
RogerLamTd Nov 26, 2022
0bf5fdd
retriable message
cyberhorsey Nov 28, 2022
d6a1ff8
added setup for testing isSignalReceived()
RogerLamTd Nov 29, 2022
8e5c594
fix
RogerLamTd Nov 30, 2022
085094b
Merge branch 'main' into testcleanup
RogerLamTd Dec 1, 2022
d3b9678
lint
cyberhorsey Dec 2, 2022
78d9e8b
switched isSignalReceived test to l1 so eth_getProof is supported
RogerLamTd Dec 5, 2022
731aab2
Merge branch 'main' into testcleanup
RogerLamTd Dec 5, 2022
80098c7
fix isSignalReceived() test
RogerLamTd Dec 5, 2022
f4a8681
fix isSignalReceived() test
RogerLamTd Dec 5, 2022
6049e3b
Update LibConstants.sol
dantaik Dec 6, 2022
714cdbc
format
dantaik Dec 6, 2022
86f0adf
finished isSignalReceived tests
RogerLamTd Dec 6, 2022
bb853a7
Merge branch 'main' into testcleanup
cyberhorsey Dec 6, 2022
103ee00
migrated repeated code to fixtures and util functions
RogerLamTd Dec 6, 2022
294254a
Merge branch 'main' into testcleanup
dantaik Dec 7, 2022
9d13030
switching eth_getProof parameter to block.number from block.hash
RogerLamTd Dec 7, 2022
c855569
Merge branch 'testcleanup' of https://github.com/taikochain/taiko-mon…
RogerLamTd Dec 7, 2022
371aee3
rename var
RogerLamTd Dec 7, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ library LibBridgeProcess {
uint256 gasLimit = msg.sender == message.owner
? gasleft()
: message.gasLimit;

bool success = LibBridgeInvoke.invokeMessageCall({
state: state,
message: message,
Expand Down
65 changes: 65 additions & 0 deletions packages/protocol/tasks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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 @@ -84,6 +86,67 @@ const MessageStatus = {
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,
Expand All @@ -94,4 +157,6 @@ export {
getSlot,
decode,
MessageStatus,
getLatestBlockHeader,
getSignalProof,
}
Loading