Skip to content

Commit

Permalink
Merge pull request #255 from hyperledger-labs/remove-ganache-tests
Browse files Browse the repository at this point in the history
Remove tests using ganache

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Feb 25, 2024
2 parents 1df6e83 + 319237a commit 8f9b8cc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 421 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
- name: Run tests with minimal solidity version
run: make SOLC_VERSION=${{ env.MINIMAL_SOLC_VERSION }} test

integration-test:
name: Integration test
e2e-test:
name: E2E test
needs: contract-test
runs-on: ubuntu-latest
steps:
Expand All @@ -73,12 +73,6 @@ jobs:
- name: Resolve dependencies
run: npm install

- name: Setup ganache-cli
run: make network-development

- name: Integration test
run: make integration-test

- name: Setup chains for E2E test
run: make network-e2e

Expand Down
37 changes: 15 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ FORGE ?= forge
SOLC_VERSION ?= 0.8.24
ABIGEN ?= "docker run -v .:/workspace -w /workspace -it ethereum/client-go:alltools-v1.11.6 abigen"
DOCKER_COMPOSE ?= docker compose
INTEGRATION_TEST_COMPOSE_FILE ?= ./chains/docker-compose.yml
E2E_TEST_COMPOSE_FILE ?= ./chains/docker-compose.yml
TEST_BROADCAST_LOG_DIR ?= ./broadcast/Deploy.s.sol
TEST_MNEMONIC ?= "math razor capable expose worth grape metal sunset metal sudden usage scheme"

######## Development ########

.PHONY: build
build:
@forge build --sizes --skip test --use solc:$(SOLC_VERSION)

.PHONY: fmt
fmt:
@$(FORGE) fmt $(FORGE_FMT_OPTS) \
./contracts/core \
./contracts/apps \
./contracts/clients \
./contracts/core \
./contracts/helpers \
./tests/foundry/src

.PHONY: lint
lint:
@npx solhint 'contracts/{apps,clients,core}/**/*.sol' 'tests/foundry/src/**/*.sol'
@$(MAKE) FORGE_FMT_OPTS=--check fmt

.PHONY: build
build:
@forge build --sizes --skip test --use solc:$(SOLC_VERSION)

.PHONY: test
test:
@forge snapshot -vvvv --gas-report --use solc:$(SOLC_VERSION) $(FORGE_SNAPSHOT_OPTION)
Expand Down Expand Up @@ -60,34 +61,26 @@ endif
.PHONY: proto-gen
proto-gen: proto-sol proto-go

######## Integration test ########
######## Abigen ########

.PHONY: network-development
network-development:
TEST_MNEMONIC=$(TEST_MNEMONIC) $(DOCKER_COMPOSE) -f $(INTEGRATION_TEST_COMPOSE_FILE) up --detach --wait development
TEST_MNEMONIC=$(TEST_MNEMONIC) $(FORGE) script --slow --use solc:${SOLC_VERSION} --fork-url http://127.0.0.1:8545 --broadcast \
./tests/foundry/src/Deploy.s.sol
.PHONY: abigen
abigen: build
ABIGEN=$(ABIGEN) ./scripts/abigen.sh

######## E2E test ########

.PHONY: network-e2e
network-e2e:
$(DOCKER_COMPOSE) -f $(INTEGRATION_TEST_COMPOSE_FILE) up --detach --wait testchain0 testchain1
$(DOCKER_COMPOSE) -f $(E2E_TEST_COMPOSE_FILE) up --detach --wait testchain0 testchain1
TEST_MNEMONIC=$(TEST_MNEMONIC) $(FORGE) script --legacy --slow --use solc:${SOLC_VERSION} --fork-url http://127.0.0.1:8645 --broadcast \
./tests/foundry/src/Deploy.s.sol
TEST_MNEMONIC=$(TEST_MNEMONIC) $(FORGE) script --legacy --slow --use solc:${SOLC_VERSION} --fork-url http://127.0.0.1:8745 --broadcast \
./tests/foundry/src/Deploy.s.sol

.PHONY: network-down
network-down:
$(DOCKER_COMPOSE) -f $(INTEGRATION_TEST_COMPOSE_FILE) down

.PHONY: integration-test
integration-test:
TEST_MNEMONIC=$(TEST_MNEMONIC) TEST_BROADCAST_LOG_DIR=$(CURDIR)/$(TEST_BROADCAST_LOG_DIR) go test -v ./tests/integration/... -count=1
$(DOCKER_COMPOSE) -f $(E2E_TEST_COMPOSE_FILE) down

.PHONY: e2e-test
e2e-test:
TEST_MNEMONIC=$(TEST_MNEMONIC) TEST_BROADCAST_LOG_DIR=$(CURDIR)/$(TEST_BROADCAST_LOG_DIR) go test -v ./tests/e2e/... -count=1

.PHONY: abigen
abigen: build
ABIGEN=$(ABIGEN) ./scripts/abigen.sh
11 changes: 0 additions & 11 deletions chains/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
services:
development:
image: trufflesuite/ganache:v7.9.0
ports:
- 8545:8545
- 8546:8546
command: --chain.chainId 1337 --chain.vmErrorsOnRPCResponse true -p 8545 -m "${TEST_MNEMONIC}"
healthcheck:
test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || exit 1" ]
interval: 100ms
timeout: 1s
retries: 100
testchain0:
build: ./besu/chain0
ports:
Expand Down
84 changes: 49 additions & 35 deletions contracts/helpers/LocalhostHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ library LocalhostHelper {
ibcHandler.createClient(
IIBCClient.MsgCreateClient({
clientType: LocalhostClientLib.CLIENT_TYPE,
protoClientState: Any.encode(Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
protoClientState: Any.encode(
Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
})
)
})
)
})),
),
protoConsensusState: LocalhostClientLib.sentinelConsensusState()
})
);
Expand All @@ -82,29 +84,37 @@ library LocalhostHelper {
ibcHandler.updateClient(
IIBCClient.MsgUpdateClient({
clientId: LocalhostClientLib.CLIENT_ID,
protoClientMessage: Any.encode(Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
protoClientMessage: Any.encode(
Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
})
)
})
)
}))
})
);
}

/**
* @dev Create a localhost connection
*/
function createLocalhostConnection(IIBCHandler ibcHandler) internal returns (string memory connectionId0, string memory connectionId1) {
function createLocalhostConnection(IIBCHandler ibcHandler)
internal
returns (string memory connectionId0, string memory connectionId1)
{
return createLocalhostConnection(ibcHandler, defaultMsgCreateConnection());
}

/**
* @dev Create a localhost connection with the localhost client
*/
function createLocalhostConnection(IIBCHandler ibcHandler, MsgCreateConnection memory msg_) internal returns (string memory connectionId0, string memory connectionId1) {
function createLocalhostConnection(IIBCHandler ibcHandler, MsgCreateConnection memory msg_)
internal
returns (string memory connectionId0, string memory connectionId1)
{
// ensure the localhost client is created
getLocalhostClient(ibcHandler);

Expand All @@ -129,14 +139,16 @@ library LocalhostHelper {
}),
delayPeriod: msg_.delayPeriod,
clientId: LocalhostClientLib.CLIENT_ID,
clientStateBytes: Any.encode(Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
clientStateBytes: Any.encode(
Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
})
)
})
)
})),
),
counterpartyVersions: getConnectionVersions(),
proofInit: LocalhostClientLib.sentinelProof(),
proofClient: LocalhostClientLib.sentinelProof(),
Expand All @@ -151,14 +163,16 @@ library LocalhostHelper {
connectionId: connectionId0,
counterpartyConnectionId: connectionId1,
version: IBCConnectionLib.defaultIBCVersion(),
clientStateBytes: Any.encode(Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
clientStateBytes: Any.encode(
Any.Data({
type_url: LocalhostClientLib.CLIENT_STATE_TYPE_URL,
value: ClientState.encode(
ClientState.Data({
latest_height: Height.Data({revision_number: 0, revision_height: uint64(block.number)})
})
)
})
)
})),
),
proofTry: LocalhostClientLib.sentinelProof(),
proofClient: LocalhostClientLib.sentinelProof(),
proofConsensus: LocalhostClientLib.sentinelProof(),
Expand All @@ -179,7 +193,10 @@ library LocalhostHelper {
/**
* @dev Create a localhost channel with the localhost client
*/
function createLocalhostChannel(IIBCHandler ibcHandler, MsgCreateChannel memory msg_) internal returns (string memory channelId0, string memory channelId1) {
function createLocalhostChannel(IIBCHandler ibcHandler, MsgCreateChannel memory msg_)
internal
returns (string memory channelId0, string memory channelId1)
{
string memory version0;
string memory version1;
(channelId0, version0) = ibcHandler.channelOpenInit(
Expand Down Expand Up @@ -230,10 +247,7 @@ library LocalhostHelper {
}

function defaultMsgCreateConnection() internal pure returns (MsgCreateConnection memory) {
return MsgCreateConnection({
version: IBCConnectionLib.defaultIBCVersion(),
delayPeriod: 0
});
return MsgCreateConnection({version: IBCConnectionLib.defaultIBCVersion(), delayPeriod: 0});
}

function getConnectionVersions() private pure returns (Version.Data[] memory) {
Expand All @@ -247,4 +261,4 @@ library LocalhostHelper {
connectionHops[0] = connectionId;
return connectionHops;
}
}
}
Loading

0 comments on commit 8f9b8cc

Please sign in to comment.