Skip to content

Commit

Permalink
Add fine-grained control of time (#88)
Browse files Browse the repository at this point in the history
* Start implementing auto-include-tx flag

* Split testnet initialization and run

* Add script to restart testnet from beginning

* Start implementing auto-include-tx flag

* Delete backup directory before taking backup

* Uncomment killing processes with app binary

* Rewrite TxQueue

* Fix fire events method

* Implement tx filtering and rechecks

* Start implementing basic test for Tx effect

* Ensure the script is not blocking

* Rename Dockerfile-test to Dockerfile.test

* Add Contains method

* Remove initial setup from Dockerfile

* Remove sleep and add -p 1

* Use big.Int for community pool size

* Use testnet restart in tests instead of a new setup each time

* Add cometmock args to be taken by startup script

* Pull time handling into TimeHandler class

* Fix CheckTx and time

* Add test cases for AutoTx and block production

* Add time control to README

* Fix auto-tx flag

* Add test for starting timestamp

* Add test for starting time=system time

(cherry picked from commit 7edb4c1)

# Conflicts:
#	Dockerfile-test
#	cometmock/abci_client/client.go
#	cometmock/main.go
#	cometmock/rpc_server/routes.go
#	e2e-tests/local-testnet-singlechain.sh
#	e2e-tests/main_test.go
  • Loading branch information
p-offtermatt authored and mergify[bot] committed Nov 27, 2023
1 parent b61229b commit af50da3
Show file tree
Hide file tree
Showing 16 changed files with 1,674 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Test binary, built with `go test -c`
*.test
!Dockerfile.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
48 changes: 48 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# import simd from ibc-go
FROM ghcr.io/cosmos/simapp:0.50.0-rc.1 AS simapp-builder

FROM golang:1.21-alpine as cometmock-builder

ENV PACKAGES curl make git libc-dev bash gcc linux-headers
RUN apk add --no-cache $PACKAGES

ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOFLAGS="-buildvcs=false"

# cache gomodules for cometmock
ADD ./go.mod /go.mod
ADD ./go.sum /go.sum
RUN go mod download

# Add CometMock and install it
ADD . /CometMock
WORKDIR /CometMock
RUN go build -o /usr/local/bin/cometmock ./cometmock

RUN apk update
RUN apk add --no-cache which iputils procps-ng tmux net-tools htop jq gcompat

FROM golang:1.21-alpine as test-env

ENV PACKAGES curl make git libc-dev bash gcc linux-headers
RUN apk add --no-cache $PACKAGES
RUN apk update
RUN apk add --no-cache which iputils procps-ng tmux net-tools htop jq gcompat

ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOFLAGS="-buildvcs=false"

ADD ./go.mod /go.mod
ADD ./go.sum /go.sum
RUN go mod download

ADD ./e2e-tests /CometMock/e2e-tests

COPY --from=simapp-builder /usr/bin/simd /usr/local/bin/simd

WORKDIR /CometMock/e2e-tests
RUN /CometMock/e2e-tests/local-testnet-singlechain-setup.sh simd ""

COPY --from=cometmock-builder /usr/local/bin/cometmock /usr/local/bin/cometmock
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ install:
go install ./cometmock

test-locally:
go test -timeout 600s ./e2e-tests -test.v
go test -timeout 600s -p 1 ./e2e-tests -test.v

test-docker:
# Build the Docker image
docker build -f Dockerfile-test -t cometmock-test .
docker build -f Dockerfile.test -t cometmock-test .

# Start a container and execute the test command inside
docker rm cometmock-test-instance || true
docker run --name cometmock-test-instance --workdir /CometMock cometmock-test go test -timeout 600s ./e2e-tests -test.v
docker run --name cometmock-test-instance --workdir /CometMock cometmock-test go test -p 1 -timeout 600s ./e2e-tests -test.v
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ CometMock was tested with `go version go1.20.3 darwin/arm64`.
To run CometMock, start your (cosmos-sdk) application instances with the flags ```--with-tendermint=false, --transport=grpc```.
After the applications started, start CometMock like this
```
cometmock [--block-time=XXX] {app_address1,app_address2,...} {genesis_file} {cometmock_listen_address} {home_folder1,home_folder2,...} {connection_mode}
cometmock [--block-time=value] [--auto-tx=<value>] [--block-production-interval=<value>] [--starting-timestamp=<value>] [--starting-timestamp-from-genesis=<value>] {app_address1,app_address2,...} {genesis_file} {cometmock_listen_address} {home_folder1,home_folder2,...} {connection_mode}
```

where:
* The `--block-time` flag is optional and specifies the time in milliseconds between blocks. The default is 1000ms(=1s). Values <= 0 mean that automatic block production is disabled. In this case, blocks can be produced by calling the `advance_blocks` endpoint or by broadcasting transactions (each transaction will be included in a fresh block). Note that all flags have to come before positional arguments.
* The `--block-time` flag is optional and specifies the time in milliseconds between the timestamps of consecutive blocks.
Values <= 0 mean that the timestamps are taken from the system time. The default value is -1.
* The `--auto-tx` flag is optional. If it is set to true, when a transaction is broadcasted, it will be automatically included in the next block. The default value is false.
* The `--block-production-interval` flag is optional and specifies the time (in milliseconds) to sleep between the production of consecutive blocks.
This does not mean that blocks are produced this fast, just that CometMock will sleep by this amount between producing two blocks.
The default value is 1000ms=1s.
* The `--starting-timestamp` flag is optional and specifies the starting timestamp of the blockchain. If not specified, the starting timestamp is taken from the system time.
* The `--starting-timestamp-from-genesis` flag is optional and can be used to override the starting timestamp of the blockchain with the timestamp of the genesis file.
In that case, the first block will have a timestamp of Genesis timestamp + block time or, if block time is <= 0, Genesis timestamp + some small, unspecified amount depending on system time.
* The `app_addresses` are the `--address` flags of the applications. This is by default `"tcp://0.0.0.0:26658"`
* The `genesis_file` is the genesis json that is also used by apps.
* The `cometmock_listen_address` can be freely chosen and will be the address that requests that would normally go to CometBFT rpc endpoints need to be directed to.
Expand Down
Loading

0 comments on commit af50da3

Please sign in to comment.