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

Add fine-grained control of time (backport #88) #92

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading