Skip to content

Commit

Permalink
Merge pull request #67 from informalsystems/mergify/bp/v0.34.x/pr-60
Browse files Browse the repository at this point in the history
Add abci_info implementation (backport #60)
  • Loading branch information
p-offtermatt authored Oct 4, 2023
2 parents 2e63187 + 52437c7 commit 0346040
Show file tree
Hide file tree
Showing 12 changed files with 1,104 additions and 37 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Automated Tests
on:
push:
branches:
- main
- v0.37.x
- v0.34.x
pull_request:
branches:
- main
- v0.37.x
- v0.34.x
# TODO: automated tests currently do not work on v0.34 because the simapp v0.45
# image is not available on dockerhub with the right platform.
# Running locally works on some platforms, fixing the automated tests is to-do.
# jobs:
# Automated_Tests:
# runs-on: ubuntu-latest
# steps:
# # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# - uses: actions/checkout@v4
# - name: Make test
# run: make test-docker
26 changes: 26 additions & 0 deletions Dockerfile-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# import simd from cosmos-sd
FROM --platform=linux/x86_64/v8 interchainio/simapp:v0.45.16 AS simapp-builder

FROM golang:1.20-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

COPY --from=simapp-builder /usr/bin/simd /usr/local/bin/simd
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
install:
go install ./cometmock
go install ./cometmock

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

test-docker:
# Build the Docker image
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
25 changes: 25 additions & 0 deletions cometmock/abci_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,31 @@ func (a *AbciClient) callClientWithTimeout(client AbciCounterpartyClient, f func
}
}

func (a *AbciClient) SendAbciInfo() (*abcitypes.ResponseInfo, error) {
if verbose {
a.Logger.Info("Sending Info to clients")
}
// send Info to all clients and collect the responses
f := func(client AbciCounterpartyClient) (interface{}, error) {
return client.Client.InfoSync(abcitypes.RequestInfo{})
}
responses, err := a.callClientsWithTimeout(f, 500*time.Millisecond)
if err != nil {
return nil, err
}

if a.ErrorOnUnequalResponses {
// return an error if the responses are not all equal
for i := 1; i < len(responses); i++ {
if !reflect.DeepEqual(responses[i], responses[0]) {
return nil, fmt.Errorf("responses are not all equal: %v is not equal to %v", responses[i], responses[0])
}
}
}

return responses[0].(*abcitypes.ResponseInfo), nil
}

func (a *AbciClient) SendBeginBlock(block *types.Block) (*abcitypes.ResponseBeginBlock, error) {
if verbose {
a.Logger.Info("Sending BeginBlock to clients")
Expand Down
9 changes: 9 additions & 0 deletions cometmock/rpc_server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var Routes = map[string]*rpc.RPCFunc{

// abci API
"abci_query": rpc.NewRPCFunc(ABCIQuery, "path,data,height,prove"),
"abci_info": rpc.NewRPCFunc(ABCIInfo, ""),

// cometmock specific API
"advance_blocks": rpc.NewRPCFunc(AdvanceBlocks, "num_blocks"),
Expand Down Expand Up @@ -501,6 +502,14 @@ func BroadcastTx(tx *types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
}, nil
}

func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
abci_client.GlobalClient.Logger.Info(
"ABCIInfo called")

response, err := abci_client.GlobalClient.SendAbciInfo()
return &ctypes.ResultABCIInfo{Response: *response}, err
}

func ABCIQuery(
ctx *rpctypes.Context,
path string,
Expand Down
File renamed without changes.
Loading

0 comments on commit 0346040

Please sign in to comment.