Skip to content

Commit

Permalink
chore: add back L1 <-> L2 tests (#627)
Browse files Browse the repository at this point in the history
* update: first test of stark sig

* ignore dump.pkl

* add invalid signature test

* finish stark sig auth test

* clean up stark sig auth test file

* add back eth sig auth test

* add eth sig auth salt reuse test

* use starknet instead of syscall for sendingn l1 message

* update all dependencies; add l1-avatar-execution first test

* add multiple txs test

* add revert if not whitelisted test

* add invalid payload test

* add invalid proposal tx

* add quorum is not met test

* add quorum not reached (against vote)

* add no votes test

* add voting period not exceeded test

* add todo comment regarding const available for the whole file

* remove only keyword

* re-enable space after disabling it in tests

* basic eth-tx-auth test

* update starknet-devnet-js

* add eth-tx-auth tests; modify metadataUri on each test

* finalize l1 <-> l2 tests

* remove extra testing step in CI

* update yarn test commands and add back L1<->L2 tests to CI

* update constants in CI

* update readme
  • Loading branch information
pscott authored Oct 3, 2024
1 parent fb5a21f commit 1c8b65d
Show file tree
Hide file tree
Showing 20 changed files with 3,935 additions and 4,436 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: SX-Starknet Workflow

env:
STARKNET_SIERRA_COMPILE_PATH: ./cairo/bin/starknet-sierra-compile
OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES
ADDRESS: "0x347be35996a21f6bf0623e75dbce52baba918ad5ae8d83b6f416045ab22961a"
PUBLIC_KEY: "0x674efe292c3c1125108916d6128bd6d1db4528db07322a84177551067aa2bef"
PK: "0xbdd640fb06671ad11c80317fa3b1799d"
ADDRESS: "0x34ba56f92265f0868c57d3fe72ecab144fc96f97954bbbc4252cef8e8a979ba"
PUBLIC_KEY: "0x5a5e37c60e77a0318643b111f88413a76af6233c891a0cfb2804106372006d4"
PK: "0xb137668388dbe9acdfa3bc734cc2c469"

on:
push:
Expand Down Expand Up @@ -93,9 +91,5 @@ jobs:
working-directory: ./starknet
run: scarb test --verbose

- name: Compile Cairo contracts for Hardhat tests
run: yarn hardhat starknet-build

# - name: run Hardhat tests
# run: yarn test:l1-execution; yarn test:eth-sig-auth; yarn test:stark-sig-auth; yarn test:eth-tx-auth
# we removed the above line because l1 <--> l2 communication is not yet implemented
- name: run Hardhat tests
run: yarn test-ts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ target
node_modules/
.env
cairo_project.toml
dump.pkl

ethereum/broadcast/

Expand Down
2 changes: 0 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
[submodule "ethereum/lib/openzeppelin-contracts-upgradeable"]
path = ethereum/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/openzeppelin-contracts-upgradeable"]
branch = v4.9.1
[submodule "ethereum/lib/zodiac"]
path = ethereum/lib/zodiac
url = https://github.com/gnosis/zodiac
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ Run tests:
forge test
```

### Run L1 <-> L2 tests and signature tests (typescript tests)

On a separate terminal, spin an L1 node (hardhat in this example, but could be anvil):
```sh
yarn hardhat node
```

Now run the tests:
```sh
yarn test-ts
```

#### Run Hardhat Tests

The Hardhat tests can be run following the procedure followed in the [CI](.github/workflows/test.yml). You will need local Starknet Devnet and Ethereum devnet instances running.
2 changes: 1 addition & 1 deletion ethereum/src/mocks/MockStarknetMessaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ contract MockStarknetMessaging is StarknetMessaging {
bytes32 msgHash = keccak256(abi.encodePacked(fromAddress, toAddress, nonce, selector, payload.length, payload));

require(l1ToL2Messages()[msgHash] > 0, "INVALID_MESSAGE_TO_CONSUME");
l1ToL2Messages()[msgHash] = 0;
l1ToL2Messages()[msgHash] -= 1;
}
}
25 changes: 2 additions & 23 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@ import dotenv from 'dotenv';
dotenv.config();
import { task } from 'hardhat/config';
import { HardhatUserConfig } from 'hardhat/types';
import '@shardlabs/starknet-hardhat-plugin';
import '@typechain/hardhat';
import '@nomicfoundation/hardhat-ethers';
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-etherscan';
import 'starknet';
import '@nomicfoundation/hardhat-toolbox';
import '@nomicfoundation/hardhat-network-helpers';
import '@nomicfoundation/hardhat-foundry';
import '@openzeppelin/hardhat-upgrades';


task('accounts', 'Prints the list of accounts', async (args, hre) => {
const accounts = await hre.ethers.getSigners();

for (const account of accounts) {
console.log(await account.getAddress());
}
});

const config: HardhatUserConfig = {
solidity: {
compilers: [
Expand Down Expand Up @@ -55,18 +43,9 @@ const config: HardhatUserConfig = {
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
starknet: {
scarbCommand: 'scarb',
network: 'starknetLocal',
recompile: false,
venv: 'active',
requestTimeout: 90_000,
},
paths: {
starknetSources: './starknet',
sources: 'ethereum/src/',
tests: './tests',
cairoPaths: ['starknet/src/'],
},
};

Expand Down
47 changes: 25 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,55 @@
"scripts": {
"format:ts": "eslint . --ext .ts --fix",
"format:json": "json-format ./tests/data/*.json",
"test:sig-auths": "jest -c jest.config.ts --runInBand",
"chain:l1": "hardhat node",
"chain:l2": "bash './scripts/chain-l2.sh'",
"chain": "yarn chain:l1 & yarn chain:l2",
"test:stark-sig-auth": "bash './scripts/stark-sig-auth-test.sh'",
"test:eth-sig-auth": "bash './scripts/eth-sig-auth-test.sh'",
"test:eth-tx-auth": "bash './scripts/eth-tx-auth-test.sh'",
"test:l1-execution": "bash './scripts/l1-avatar-execution-test.sh'"
"test:l1-execution": "bash './scripts/l1-avatar-execution-test.sh'",
"test-ts": "yarn test:stark-sig-auth && yarn test:eth-sig-auth && yarn test:eth-tx-auth && yarn test:l1-execution"
},
"devDependencies": {
"@gnosis.pm/safe-contracts": "^1.3.0",
"@gnosis.pm/zodiac": "^3.3.7",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@gnosis.pm/zodiac": "^4.0.3",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/ignition-core": "^0.15.5",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/hardhat-upgrades": "^3.2.0",
"@safe-global/safe-contracts": "^1.4.1-build.0",
"@shardlabs/starknet-hardhat-plugin": "0.8.0-alpha.4",
"@snapshot-labs/sx": "^0.1.0-beta.46",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/mocha": "^10.0.7",
"@types/node": "^20.4.5",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/hardhat-upgrades": "^3.2.0",
"axios": "^1.5.0",
"chai": "^4.3.7",
"chai": "4",
"concurrently": "^7.0.0",
"dotenv": "^16.3.1",
"eslint": "^8.46.0",
"eslint-plugin-prettier": "^5.0.0",
"ethereum-waffle": "^4.0.10",
"ethers": "^6.13.2",
"fs": "^0.0.1-security",
"hardhat": "^2.17.2",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-gas-reporter": "^1.0.8",
"json-format-cli": "^1.1.1",
"micro-starknet": "^0.2.3",
"prettier": "^3.0.0",
"starknet": "^5.24.3",
"solidity-coverage": "^0.8.12",
"starknet": "^6.11.0",
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.1.6",
"wait-on": "^7.0.1"
},
"dependencies": {
"starknet-devnet": "^0.1.2"
}
}
3 changes: 0 additions & 3 deletions scripts/chain-l2.sh

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/eth-sig-auth-test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash

kill -9 $(lsof -t -i:5050)
yarn chain:l2 &
sleep 10 &&
yarn hardhat test tests/eth-sig-auth.test.ts
if [ $? -eq 0 ]
then
Expand Down
6 changes: 3 additions & 3 deletions scripts/eth-tx-auth-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

kill -9 $(lsof -t -i:8545)
kill -9 $(lsof -t -i:5050)
yarn chain &
sleep 10 &&
yarn hardhat test tests/eth-tx-auth.test.ts --network 'ethereumLocal' --starknet-network 'starknetLocal'
yarn hardhat node &
sleep 5 &&
yarn hardhat test tests/eth-tx-auth.test.ts --network 'ethereumLocal'
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:8545)
Expand Down
6 changes: 3 additions & 3 deletions scripts/l1-avatar-execution-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

kill -9 $(lsof -t -i:8545)
kill -9 $(lsof -t -i:5050)
yarn chain &
sleep 10 &&
yarn hardhat test tests/l1-avatar-execution.test.ts --network 'ethereumLocal' --starknet-network 'starknetLocal'
yarn hardhat node &
sleep 5 &&
yarn hardhat test tests/l1-avatar-execution.test.ts --network 'ethereumLocal'
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:8545)
Expand Down
2 changes: 0 additions & 2 deletions scripts/stark-sig-auth-test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash

kill -9 $(lsof -t -i:5050)
yarn chain:l2 &
sleep 10 &&
yarn hardhat test tests/stark-sig-auth.test.ts
if [ $? -eq 0 ]
then
Expand Down
4 changes: 2 additions & 2 deletions starknet/src/execution_strategies/eth_relayer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ mod EthRelayerExecutionStrategy {
votes_abstain.serialize(ref l1_payload);
l1_execution_hash.serialize(ref l1_payload);

syscalls::send_message_to_l1_syscall(l1_execution_strategy.into(), l1_payload.span())
.unwrap_syscall();
starknet::send_message_to_l1_syscall(l1_execution_strategy.into(), l1_payload.span())
.unwrap();
}

fn get_strategy_type(self: @ContractState) -> felt252 {
Expand Down
Loading

0 comments on commit 1c8b65d

Please sign in to comment.