Skip to content

Commit

Permalink
Remove code involving ganache/truffle (#3437)
Browse files Browse the repository at this point in the history
* Remove code involving ganache/truffle

* remove certusone/wormhole-sdk dependency'

* Add ethereum tests foundry (#3439)

* WIP

* correct openzeppelin version

* Fix Relayer Test
  • Loading branch information
derpy-duck committed Oct 17, 2023
1 parent d71ea78 commit 928a208
Show file tree
Hide file tree
Showing 49 changed files with 5,915 additions and 54,247 deletions.
14 changes: 3 additions & 11 deletions ethereum/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lib/forge-std:
forge install foundry-rs/[email protected] --no-git --no-commit

lib/openzeppelin-contracts:
forge install openzeppelin/openzeppelin-contracts@0457042d93d9dfd760dbaa06a4d2f1216fdbe297 --no-git --no-commit
forge install openzeppelin/openzeppelin-contracts@v4.3.1 --no-git --no-commit

dependencies: node_modules forge_dependencies

Expand All @@ -61,15 +61,7 @@ flattened: $(patsubst contracts/%, flattened/%, $(FLATTEN_FILES))
.env: .env.test
cp $< $@

test: test-forge test-identifiers # test-ganache

.PHONY: test-ganache
test-ganache: build .env dependencies
@if pgrep ganache-cli; then echo "Error: ganache-cli already running. Stop it before running tests"; exit 1; fi
. ./.env && npx ganache-cli --chain.vmErrorsOnRPCResponse --chain.chainId $$INIT_EVM_CHAIN_ID --wallet.defaultBalance 10000 --wallet.deterministic --chain.time="1970-01-01T00:00:00+00:00" --chain.asyncRequestProcessing=false > ganache.log &
sleep 5
npm test || (pkill ganache-cli && exit 1)
pkill ganache-cli || true
test: test-forge test-identifiers

.PHONY: test-upgrade
test-upgrade: build .env node_modules
Expand All @@ -86,4 +78,4 @@ test-forge: dependencies
forge test --no-match-test .*_KEVM # ignore KEVM tests (see PROOFS.md)

clean:
rm -rf ganache.log .env node_modules build flattened build-forge ethers-contracts lib/forge-std lib/openzeppelin-contracts
rm -rf .env node_modules build flattened build-forge ethers-contracts lib/forge-std lib/openzeppelin-contracts
10 changes: 4 additions & 6 deletions ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ To build the contracts:
### Deploying

To deploy the bridge on Ethereum you first need to compile all smart contracts:
`npx truffle compile`
`npm run build:forge`

To deploy you can either use the bytecode from the `build/contracts` folder or the oz cli `oz deploy <Contract>`
To deploy you can either use the bytecode from the `build-forge/` folder or the oz cli `oz deploy <Contract>`
([Documentation](https://docs.openzeppelin.com/learn/deploying-and-interacting)).

You first need to deploy one `Wrapped Asset` and initialize it using dummy data.
Expand All @@ -31,13 +31,11 @@ assets.

For each test run:

Run `npx ganache-cli --chain.vmErrorsOnRPCResponse --chain.chainId 1 --wallet.defaultBalance 10000 --wallet.deterministic --chain.time="1970-01-01T00:00:00+00:00" --chain.asyncRequestProcessing=false` to start a chain.
Run `anvil --host=0.0.0.0 --accounts=11 --chain-id=1 --block-time=1 --mnemonic="myth like bonus scare over problem client lizard pioneer submit female collect"` to start a chain.

Run the all ethereum tests using `DEV=True make test`

Run a specific test file using `npx truffle test test/wormhole.js`

Run a specific test file while skipping compile `npx truffle test test/wormhole.js --compile-none`
See https://book.getfoundry.sh/reference/forge/forge-test for options on running specific tests

### User methods

Expand Down
4 changes: 2 additions & 2 deletions ethereum/forge-scripts/devnetInitialization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ source "./forge-scripts/registerChainsNFTBridge.sh"
echo 'Registration of NFT bridges done';

if [ $CHAIN_ID -eq 4 ]; then
ENV=kubernetes npm run deploy-relayers-evm2
ENV=kubernetes CONTAINER=evm2 bash ./ts-scripts/relayer/shell/deployInContainer.sh
else
ENV=kubernetes npm run deploy-relayers-evm1
ENV=kubernetes CONTAINER=evm1 bash ./ts-scripts/relayer/shell/deployInContainer.sh
fi

nc -lkn 2000
54 changes: 54 additions & 0 deletions ethereum/forge-test/Implementation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,58 @@ contract TestImplementation is TestUtils {
vm.expectRevert();
proxied.publishMessage{value: messageFee}(nonce, payload, consistencyLevel);
}

function testShouldBeInitializedWithCorrectSignersAndValues() public {
uint32 index = proxied.getCurrentGuardianSetIndex();
IWormhole.GuardianSet memory set = proxied.getGuardianSet(index);

// check set
assertEq(set.keys.length, 1, "Guardian set length wrong");
assertEq(set.keys[0], vm.addr(testGuardian), "Guardian wrong");

// check expiration
assertEq(set.expirationTime, 0);

// chain id
uint16 chainId = proxied.chainId();
assertEq(chainId, 2, "Wrong Chain ID");

// evm chain id
uint256 evmChainId = proxied.evmChainId();
assertEq(evmChainId, 1, "Wrong EVM Chain ID");

// governance
uint16 governanceChainId = proxied.governanceChainId();
bytes32 governanceContract = proxied.governanceContract();
assertEq(governanceChainId, 1, "Wrong governance chain ID");
assertEq(governanceContract, 0x0000000000000000000000000000000000000000000000000000000000000004, "Wrong governance contract");
}

function testShouldLogAPublishedMessageCorrectly() public {
vm.expectEmit();
emit LogMessagePublished(address(this), uint64(0), uint32(291), bytes(hex"123321"), uint8(32));
proxied.publishMessage(0x123, hex"123321", 32);
}

function testShouldIncreaseTheSequenceForAnAccount() public {
proxied.publishMessage(0x1, hex"01", 32);
uint64 sequence = proxied.publishMessage(0x1, hex"01", 32);
assertEq(sequence, 1, "Sequence number didn't increase");
}

function testParseVMsCorrectly() public {
uint32 timestamp = 1000;
uint32 nonce = 1001;
uint16 emitterChainId = 11;
bytes32 emitterAddress = 0x0000000000000000000000000000000000000000000000000000000000000eee;
uint64 sequence = 25;
uint8 consistencyLevel = 32;
bytes memory data = hex"aaaaaa";

bytes memory body = abi.encodePacked(timestamp, nonce, emitterChainId, emitterAddress, sequence, consistencyLevel);
bytes32 bodyHash = keccak256(abi.encodePacked(keccak256(body)));



}
}
3 changes: 0 additions & 3 deletions ethereum/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ evm_version = "paris"
out = 'build-forge'
libs = ['lib', 'node_modules']
remappings = [
'@solidity-parser/=node_modules/@solidity-parser/',
'ds-test/=lib/forge-std/lib/ds-test/src/',
'forge-std/=lib/forge-std/src/',
'@openzeppelin/=lib/openzeppelin-contracts/',
'truffle/=node_modules/truffle/',
]
fs_permissions = [{ access = "read", path = "./"}]

[fmt]
line_length = 100
Expand Down
15 changes: 0 additions & 15 deletions ethereum/migrations/10_deploy_batched_vaa_sender.js

This file was deleted.

6 changes: 0 additions & 6 deletions ethereum/migrations/1_initial_migration.js

This file was deleted.

34 changes: 0 additions & 34 deletions ethereum/migrations/2_deploy_wormhole.js

This file was deleted.

42 changes: 0 additions & 42 deletions ethereum/migrations/3_deploy_bridge.js

This file was deleted.

40 changes: 0 additions & 40 deletions ethereum/migrations/4_deploy_nft_bridge.js

This file was deleted.

13 changes: 0 additions & 13 deletions ethereum/migrations/6_deploy_bridge_implementation_only.js

This file was deleted.

13 changes: 0 additions & 13 deletions ethereum/migrations/7_deploy_token_implementation_only.js

This file was deleted.

5 changes: 0 additions & 5 deletions ethereum/migrations/9_deploy_weth9.js

This file was deleted.

Loading

0 comments on commit 928a208

Please sign in to comment.