Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
df74328
feature: start the cosmos relay version
prestwich Sep 19, 2019
2147869
features: ongoing work on barebones sdk module
prestwich Sep 22, 2019
9bf6112
feature: finish up basic module development
prestwich Sep 22, 2019
0b0b7a6
chore: consistent naming
prestwich Sep 22, 2019
2a721d9
feature: SetLink and GetParent work now
prestwich Sep 23, 2019
caa37ed
chore: README with notes on adding txns and queries
prestwich Sep 23, 2019
4a714d7
chore: add TODOs to README
prestwich Sep 23, 2019
8bee349
adding getters and setters
ErinHales Sep 23, 2019
1616542
added getters and setters, getting errors
ErinHales Sep 23, 2019
a445387
feature: rewrite some getters and setters
prestwich Oct 2, 2019
0e1c510
Merge pull request #2 from summa-tx/getters-setters-improvements
prestwich Nov 11, 2019
9cbf749
bug: correct alias of MsgSetLink
prestwich Nov 11, 2019
de20ac6
refactor: improve Hash256 handling in keeper and querier
prestwich Nov 11, 2019
f98b549
refactor: keeper split into multiple prefixed stores
prestwich Nov 12, 2019
578c669
feature: continue working on link and header store
prestwich Nov 13, 2019
5afeadd
feature: header chain validation for ingestion
prestwich Nov 18, 2019
ec44fb5
bug: reintroduce concept of external call
prestwich Nov 18, 2019
092fc52
feature: better genesis state handling
prestwich Nov 18, 2019
cd32287
feature: Reorg and Extension events
prestwich Nov 18, 2019
3dcf2c6
Merge pull request #1 from summa-tx/getters-setters
prestwich Nov 18, 2019
e01b519
refactor: break out events instantiation into the types module
prestwich Nov 19, 2019
e429386
feature: testnet mode scaffolding
prestwich Nov 19, 2019
a2dafe4
feature: LCA getter and setter
prestwich Nov 19, 2019
f8f5d64
refactor: break out common blocks from getters/setters
prestwich Nov 19, 2019
1fa4fce
feature: MarkNewHeaviest
prestwich Nov 20, 2019
081d5ae
feature: IsAncestor and FindAncestor
prestwich Nov 20, 2019
55f1726
feature: make private functions public in chain.go
prestwich Nov 20, 2019
7e77730
made function skeletons
ErinHales Nov 26, 2019
d2b9f4b
mostly wrote functions
ErinHales Nov 26, 2019
27d0566
Added function skeletons in querier.go
ErinHales Nov 27, 2019
b501c5d
mostly wrote querier functions, need to fix errors
ErinHales Nov 27, 2019
3726ac6
Merge branch 'golang' into golang-messages
ErinHales Nov 27, 2019
ffb42cd
added types
ErinHales Nov 27, 2019
0c9e73a
refactor: walkthrough messages and queries
prestwich Nov 27, 2019
158821e
finished writing messages
ErinHales Nov 27, 2019
00ff099
added handlers
ErinHales Nov 27, 2019
0579858
deleted old code, fixed errors in querier.go
ErinHales Nov 27, 2019
b07cf4f
fixed stuff
ErinHales Nov 28, 2019
a704ec4
missed btcspv error
ErinHales Nov 28, 2019
641a324
fix errors, fix typos
ErinHales Nov 29, 2019
89e589f
fixed missing type error in query.go
ErinHales Nov 29, 2019
0d48473
Merge pull request #7 from summa-tx/golang-messages
prestwich Nov 30, 2019
081d5fa
tests: scaffolding for keeper tests, break out validation into statel…
prestwich Nov 30, 2019
a8d27d7
tests: first test for headers.go
prestwich Nov 30, 2019
24c2769
tests: first test for validateDifficultyChange
prestwich Nov 30, 2019
8ef8066
tests: add test case comments and the NamedCase interface
prestwich Dec 1, 2019
1e1b559
tests: suite no longer panics if expected error doesn't exist, many m…
prestwich Dec 1, 2019
b8a1a5e
refactor: trim app.go to make a one-module app suitable for integrati…
prestwich Dec 2, 2019
da9c40c
Merge pull request #8 from summa-tx/test-scaffolding-golang
prestwich Dec 2, 2019
c712766
Merge pull request #10 from summa-tx/trim-app-to-sim
ErinHales Dec 2, 2019
d71619d
Add Golang Queries (#9)
ErinHales Dec 2, 2019
bd4d010
added tests, added docs in types/querier
ErinHales Dec 3, 2019
03e5eaa
updated error comparisons
ErinHales Dec 3, 2019
5155b5f
Cli rest queries (#12)
prestwich Dec 5, 2019
493a8cf
WIP: Cli rest messages (#18)
prestwich Dec 5, 2019
daa35e0
WIP: Keeper tests (#19)
ErinHales Jan 3, 2020
98a7ce1
Proof request (#25)
ErinHales Jan 10, 2020
7271e6f
Add messages to CLI (#26)
ErinHales Jan 15, 2020
df01e45
chore: update progress tracking in README
prestwich Jan 15, 2020
c5411dc
Request tests (#31)
ErinHales Jan 22, 2020
55fc0b4
Proof Validator (#24)
ErinHales Jan 29, 2020
7a4a18b
Expose difficulty golang (#33)
ErinHales Jan 29, 2020
d66f129
chore: swallow errors to make linter happy
prestwich Jan 29, 2020
b1aa3fc
chore: update README
prestwich Mar 13, 2020
7c9923c
dependency: bump version of btcspv, refactor for new API (#35)
prestwich Mar 13, 2020
fad244a
Merge branch 'master' into golang
prestwich Mar 13, 2020
4e17aa1
Merge branch 'master' into golang
prestwich Mar 13, 2020
2ba8f90
Merge branch 'master' into golang
prestwich Mar 13, 2020
f7e120b
Merge branch 'master' into golang
prestwich Mar 16, 2020
ab9ac96
plumbing: ProvideProof functionality
ewilz Mar 13, 2020
8cfba5c
chore: update README and comments
prestwich Mar 16, 2020
52ffd69
chore: add export comments
prestwich Mar 16, 2020
fc9a369
plumbing: checkrequests query functionality
ewilz Mar 17, 2020
a0889e6
plumbing: checkProof functionality
ewilz Mar 19, 2020
87e2f17
enhancement: (IBC) prep requests with Origin + Action for event dispa…
ewilz Mar 20, 2020
e0c44d5
chore: comment and lint cleanup
prestwich Mar 24, 2020
a6a627c
Update golang README (#46)
ewilz Mar 25, 2020
8c4e402
Prepare Manual Testing (#45)
ewilz Mar 27, 2020
00f4a98
Merge branch 'master' into golang
prestwich Mar 30, 2020
2446122
feature: getBestKnownDigest query (#54)
prestwich Apr 1, 2020
764ad4a
tests: fix tests I broke in a previous PR (#55)
prestwich Apr 1, 2020
7d9c483
Makefile command for initializing chain (#53)
ewilz Apr 2, 2020
2ffe884
feature: #48 add a ProofProvided event (#56)
prestwich Apr 3, 2020
02ac946
Merge branch 'master' into golang
prestwich Apr 7, 2020
fd4e493
Merge pull request #59 from summa-tx/golang
ErinHales Apr 7, 2020
75e51a0
version: bump solidity to v2.0.1
prestwich Apr 7, 2020
63ed208
feature: alfajores migrations
prestwich Apr 8, 2020
4939e3e
bug: fix imports in maintainer
prestwich Apr 8, 2020
7cd0939
bug:add missing setup.py
prestwich Apr 8, 2020
89864d1
bug: fix migration for alfajores always using testnet
prestwich Apr 8, 2020
abc4163
feature: hint on bad header forwarder setup
prestwich Apr 8, 2020
a7c627b
dep: bump bitcoin-spv-py to 3.0.1
prestwich Apr 8, 2020
fd5ef74
bug: make bcoin function accept LE hash
prestwich Apr 8, 2020
0958007
feature: make LE/BE hash explicit in bcoin call
prestwich Apr 8, 2020
c2a89f7
refactor: move towards standardizing on LE
prestwich Apr 8, 2020
c2e0e71
chore: new ABI version
prestwich Apr 8, 2020
528fbcf
bug: remove sub expired event
prestwich Apr 8, 2020
fa65067
refactor: break out find LCA and add rate limit and error condition
prestwich Apr 8, 2020
2203963
refactor: move maintainer into a subdir
prestwich Apr 9, 2020
2150c92
chore: update readmes about maintainer python
prestwich Apr 9, 2020
6dfe670
chore: bump mainnet trusted block
prestwich Apr 10, 2020
07751a9
bug: missing 0x prefix on hex bytes
prestwich Apr 10, 2020
3406fbe
bug: redundant port in truffle-config
prestwich Apr 10, 2020
6c32f9f
feature: update celo to use mnemonic provider instead of unlocked node
prestwich Apr 10, 2020
3b51c92
update btcspv in go (#60)
ErinHales Apr 13, 2020
96a84ae
Integration tests (#57)
ewilz Apr 13, 2020
8ce42b7
chore: add more information to READMEs
prestwich Apr 13, 2020
8a837a2
chore: add note about golang + solidity relay
prestwich Apr 13, 2020
4cf1570
chore: update READMEs
prestwich Apr 13, 2020
7a5e48c
Travis-CI Integration (#64)
ewilz Apr 14, 2020
f44331a
dep: bump soliditycoverage to use truffle plugin (#67)
prestwich Apr 14, 2020
d60b9c2
Tests for OnDemandSPV (#69)
prestwich Apr 14, 2020
6231b48
lint: fix solidity indentation in test contract (#71)
prestwich Apr 14, 2020
fe51def
Summary keeper files (#70)
ErinHales Apr 14, 2020
f0219d1
Proof handler interface (#73)
prestwich Apr 14, 2020
558ba2c
Fix TravisCI lint race condition (#77)
ewilz Apr 15, 2020
99063da
use Strip0xPrefix from btcspv (#75)
ErinHales Apr 15, 2020
bea8b7d
chore: update README to mention golang version
prestwich Apr 15, 2020
38654bb
Add more details to Error messages (#76)
ewilz Apr 16, 2020
3eaa33a
Set up Dockerfile for deploying relay
Shadowfiend Apr 7, 2020
2e5a87b
Only auth on bcoin node if auth is available
Shadowfiend Apr 17, 2020
736fdb4
Fix env file path for maintainer deployment
Shadowfiend Apr 17, 2020
fa97cb9
Await transaction result
lukasz-zimnoch May 5, 2020
2bc583d
Update genesis blocks
lukasz-zimnoch May 5, 2020
1e177ed
Merge pull request #1 from keep-network/await-tx-result
Shadowfiend May 6, 2020
3ed8800
More gas
May 13, 2020
efea3a8
Merge pull request #2 from keep-network/sthompson22/moar-gas
May 13, 2020
bc881b9
Add super-basic gas management to ethereum/shared.py
Shadowfiend May 14, 2020
543f2c8
Start INCOMPLETE_TX_COUNT at pending transaction count
Shadowfiend May 20, 2020
d8bf22f
Replace pending relay transactions on boot
Shadowfiend May 20, 2020
afa04b9
Track completed/pending nonce to use for gas boost
Shadowfiend May 20, 2020
56c7499
Properly compute initial gas price
Shadowfiend May 20, 2020
0a08522
Add some nonce/pending transaction info logging
Shadowfiend May 20, 2020
b966feb
n is not a nonce
Shadowfiend May 20, 2020
03b371e
Fix an off-by-one for starting nonce
Shadowfiend May 20, 2020
e7e5f05
await sign_and_broadcast in _track_tx_result
Shadowfiend May 20, 2020
bae3647
Don't try catching up nonces if already caught up
Shadowfiend May 20, 2020
60e2c8b
Boost gas price even if a transaction waits alone
Shadowfiend May 20, 2020
a5b03ea
Drop LATEST_COMPLETED_NONCE global
Shadowfiend May 21, 2020
e61f16d
Ensure adjusted_gas_price is an integer
Shadowfiend May 21, 2020
49ff5f0
Fix a comment typo, Brad does not cast
Shadowfiend May 21, 2020
1d7a288
Fix a bad reference to UnsignedTx.gasPrice
Shadowfiend May 21, 2020
03831de
Close the loop for ongong gas price increases
Shadowfiend May 21, 2020
57095cd
Add additional nonce/gas price logging
Shadowfiend Jul 29, 2020
419b572
Underpriced transactions go down the gas-bump path
Shadowfiend Jul 29, 2020
49371c7
Track gas-bumped transactions
Shadowfiend Jul 29, 2020
019273a
Don't crash if an LCA isn't found in 5 attempts
Shadowfiend Jul 29, 2020
5b5e406
Log mined tx count at startup
Shadowfiend Jul 30, 2020
578afea
Aggressively clear unmined txes during gas bumping
Shadowfiend Jul 30, 2020
780cdaa
Fix mined_tx_count
Shadowfiend Jul 31, 2020
8378b91
Handle already known errors like transaction underpriced errors
Shadowfiend Jul 31, 2020
4671224
Do not crash on nonce too low errors
Shadowfiend Jul 31, 2020
1fbf2e5
Include nonce + gas price info in a few logs
Shadowfiend Jul 31, 2020
dfeb45f
Gas price factor is now (txes ahead) * ticks
Shadowfiend Jul 31, 2020
55fd491
When catching up to existing txes, don't wait 30s
Shadowfiend Jul 31, 2020
1895bdf
Switch an await to an ensure_future
Shadowfiend Jul 31, 2020
b133349
Add logging and retries when boosting gas to match existing tx
Shadowfiend Jul 31, 2020
d2d39e1
Set max gas to 120 gwei
Shadowfiend Jul 31, 2020
e7d25b9
Merge pull request #4 from keep-network/gas-attack
pdyraga Aug 7, 2020
3a85e32
Bump default and max gas prices
Shadowfiend Sep 14, 2020
5598b90
Bump gas per wait unit more aggressively
Shadowfiend Sep 14, 2020
4bfcf6d
Merge pull request #5 from keep-network/molotov-cocktail
pdyraga Sep 14, 2020
339b9f4
added local_test configuration for contracts
tomaszslabon Mar 9, 2021
44c652c
manual-setup of Relay Maintainer locally
tomaszslabon Mar 11, 2021
9c1d65e
Minor update od manual-setup doc
tomaszslabon Mar 11, 2021
350ce2b
Merge pull request #7 from keep-network/add-configuration-for-running…
lukasz-zimnoch Mar 24, 2021
341175a
Merge pull request #9 from keep-network/add_docs_for_local_setup_of_r…
lukasz-zimnoch Mar 24, 2021
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
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
matrix:
include:
- language: go
go: 1.13.1
env:
- GO111MODULE=on
before_script:
- cd golang
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.20.0
- make install
script:
- make lint
- go test ./x/relay/keeper
- go test ./x/relay/types
- go test -mod=readonly `go list ./cli_test/...`

- language: node_js
node_js: 10.14.2
before_script:
- cd solidity
- npm install -g truffle
- npm install
script:
- npm run lint
- npm run test
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This is a Bitcoin Relay. It uses 1 + 1/n slots per header relayed (n is
currently 4), and 2 slots to externalize useful information (best chain tip and
best shared ancestor of latest reorg).

At present, only a Solidity implementation is available, but we intend to add
more implementations soon :)
Implementations are available in Solidity (for EVM chains) and Golang using the
cosmos-sdk framework.

### How does it work?

Expand Down Expand Up @@ -43,11 +43,8 @@ reducing calldata gas costs.

### Project Notes

The Python relay mainter in `./relay/` is not thoroughly tested, and does not
yet support the cosmos-sdk relay.
Complete relays are available in Solidity, for EVM-based chains (like Ethereum)
and Golang using the cosmos-sdk framework.

### How do I develop for it?

install `pipenv` and `pyenv`

$ pipenv install --python=$(pyenv which python3.7)
The Python relay mainter in `./maintainer/` is not thoroughly tested, and does
not yet support the cosmos-sdk relay.
3 changes: 3 additions & 0 deletions golang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.test

/x/relay/keeper/coverage.out
110 changes: 110 additions & 0 deletions golang/EXTENDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
## Adding new functionality

This is a cosmos-sdk module. It can be extended with new messages and/or
queries. Generally, this module is feature-complete, and should not be
extended. The main exception is the WIP hooks system on proof validation. All
other functionality should likely be put into a separate module.

### Integrating with other modules

The relay keeper keeps a reference to an object that implements the following
interface (found in `x/types/types.go`).

```go
type ProofHandler interface {
HandleValidProof(ctx sdk.Context, filled FilledRequests, requests []ProofRequest)
}
```

The `FilledRequests` struct contains an `SPVProof` and supporting information
about the transaction that fulfills the request.
It can be found in `x/types/validator.go`. `requests []ProofRequest` is a slice
of `ProofRequest`s that have been filled.

When the keeper validates a proof, it will call the `HandleValidProof` function
with the valid `FilledRequests` struct and the `ProofRequests` that have been
filled.

First, instantiate a `handler` that fulfills the `ProofHandler` interface. Then
add an instance of `relay.Keeper` to your app in `app.go`. It can be
instantiated as follows:

```go
handler = types.NewNullHandler() // or your preferred handler

app.relayKeeper = relay.NewKeeper(
keys[relay.StoreKey],
app.cdc,
true,
handler
)
```

After that, the relay can be accessed via the Keeper's public interface.

### Extending this module

In order to extend this module, follow these steps:

## How to add a view function (queries)
1. Add necessary getter(s) in `x/relay/keeper/keeper.go`
1. Add response type to `x/relay/types/querier.go`
1. Add new string tag for the new query
1. Response type is a struct with the return values
1. Implement `String()` for the response type
1. Add function to querier `x/relay/keeper/querier.go`
1. Add new `query___` function
1. Add new case block to `switch` in `NewQuerier()`
1. Add to CLI
1. add to `x/relay/client/cli/query.go`
1. `func GetCmd______`
1. returns a `cobra.Command` object
1. define `Use` `Example` `Short` `Long` `Args` and `RunE`
1. `RunE` parses args, returns errors, and calls `cliCtx.QueryWithData`
1. parses the output and returns it with `cliCtx.PrintOutput`
1. Add to REST
1. add to `x/relay/client/rest/query.go`
1. new function `_____Handler`
1. parse args and build structs
1. cliCtx.QueryWithData
1. return errors with `rest.WriteErrorResponse`
1. return query result with `rest.PostProcessResponse`
1. add GET route to `x/relay/client/rest/rest.go`
1. new `s.HandleFunc` with the route and arguments
1. `.Methods("GET")`
1. duplicate for optional args (see `isancestor` for example)


## How to add a non-view function (messages)
1. Add necessary getters/setters in `x/relay/keeper/keeper.go`
1. Add msg type in `x/relay/types/msgs.go`
1. Message type is a struct with the arguments
1. Implement `New___()`
1. Implement `GetSigners()` <--- Ask me about this later
1. Implement `Type()`
1. Implement `ValidateBasic()`
1. Implement `GetSignBytes()`
1. Implement `Route()`
1. Add to handler
1. Add new `handle____` function
1. Add new case block to `switch` in `NewHandler()`
1. Add aliases in `x/relay/alias.go`
1. Add alias in `var` block
1. Add alias in `type` block
1. Add to CLI
1. add to `x/relay/client/cli/tx.go`
1. `func GetCmd______`
1. returns a `cobra.Command` object
1. define `Use` `Example` `Short` `Long` `Args` and `RunE`
1. `RunE` parses args, returns errors, and calls `utils.GenerateOrBroadcastMsgs`
1. Add to REST
1. add to `x/relay/client/rest/tx.go`
1. new http request struct `______Req`
1. `BaseReq` + the struct from `x/relay/types/msgs.go`
1. new function `_____Handler`
1. parse args and build structs
1. return errors with `rest.WriteErrorResponse`
1. make the tx with `utils.WriteGenerateStdTxResponse`
1. add POST route to `x/relay/client/rest/rest.go`
1. new `s.HandleFunc` with the route and arguments
1. `.Methods("POST")`
33 changes: 33 additions & 0 deletions golang/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PACKAGES=$(shell go list ./... | grep -v '/simulation')

VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=Relay \
-X github.com/cosmos/cosmos-sdk/version.ServerName=relayd \
-X github.com/cosmos/cosmos-sdk/version.ClientName=relaycli \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT)

BUILD_FLAGS := -ldflags '$(ldflags)'

all: lint install

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/relayd
go install -mod=readonly $(BUILD_FLAGS) ./cmd/relaycli

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify

lint:
golangci-lint run
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify

test:
@go test -mod=readonly $(PACKAGES)

init:
./scripts/init_chain.sh
114 changes: 114 additions & 0 deletions golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
## cosmos-sdk Bitcoin Relay

This is a full-featured Bitcoin relay module for cosmos-sdk chains. It indexes
Bitcoin headers, provides information about the latest-known state of the
Bitcoin chain, and validates SPV Proofs against its view of the chain. It is a
critical component for many Cosmos applications to interact with Bitcoin.

For more information about the relay's architecture see the `README.md` in the
repo's root directory.

## Building the daemon and cli

```sh
$ make
# To additionally install them in your `$GOPATH/bin` directory:
$ make install
```

## Running tests

Run the unit tests as follows:

```sh
$ go test ./x/...
```

See the README in `./cli_test` for instructions on running the integration
tests.

Instructions for setting up manual testing can be found in the README in
`./scripts`.

## Project Status

- [X] Milestone 1
- [X] Milestone 2
- - [X] Expose best-known digest
- - [X] Expose LCA of reorg
- - [X] Follow API of existing Solidity Relay
- - [X] Validate SPV Proofs
- - [X] `ProvideProof` message
- [ ] Milestone 3
- - [X] Provide tooling for manual testing (scripts, docs, json test files)
- - [X] Integration Tests
- - [ ] Document relay design & architecture
- - [X] Document public interface
- - [X] Provide hooks to execute tasks + dispatch messages
- - [ ] Add a basic web dashboard with Relay health


## API

Cosmos modules expose messages, which modify state, and queries, which read
state.

### Queries

Queries are available via CLI or REST. For more information, see the
descriptions in the CLI.

| Query | Description |
| ----- | ----------- |
| IsAncestor | Deteremine if a block is an ancestor of another |
| GetRelayGenesis | Get the trusted root of the relay |
| GetLastReorgLCA | Get the LCA of the latest reorg |
| GetLastReorgLCA | Get the best digest known to the relay |
| FindAncestor | Find the nth ancestor of a block|
| IsMostRecentCommonAncestor | Determine if a block is the LCA of two headers|
| HeaviestFromAncestor | Check which of two descendents is heaviest from the LCA |
| GetRequest | Get details of an SPV Proof Request|
| CheckProof | Check the syntactic validity of an SPV Proof |
| CheckRequests | Perform CheckProof and check the SPV Proof against a set of Requests |

### Messages

Messages are available via CLI or REST. For more information, see the
descriptions in the CLI.

| Message | Description |
| ------- | ----------- |
| IngestHeaderChain | Add a chain of headers to the relay |
| IngestDifficultyChange | Add a chain of headers to the relay with a difficulty change|
| MarkNewHeaviest | Mark a new best-known chain tip |
| NewRequest | Register a new SPV Proof request |
| ProvideProof | Provide a proof that satisfies 1 or more requests |

## Project Overview

### Keeper
High-level overview of the project structure within the `keeper` file.

#### Keeper.go
Instantiates a `keeper` (what handles interaction with the store and contains most of the core functionality of the module). It also handles the genesis state for the relay.

#### Headers.go
Handles the storage and validation of Bitcoin Headers and Header Chains.

#### Chain.go
Checks and updates information about the chain. Provides functionality to ensure we are using the heaviest chain.

#### Links.go
Sets and retrieves data about each link in the chain. This is most commonly used to check information about ancestors.

#### Requests.go
Stores, retrieves, and validates requests.

#### Validator.go
Contains validation functions. Currently, this can validate SPV Proofs and Requests.

#### Handler.go
Handles messages.

#### Querier.go
Handles queries.
56 changes: 56 additions & 0 deletions golang/cli_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Relay CLI Integration tests

The relay cli integration tests live in this folder. You can run the full suite by running:

```bash
go test -mod=readonly -p 4 `go list ./cli_test/...`
```

To run a single test run:
```bash
go test -mod=readonly -p 4 `go list ./cli_test/...` -testify.m TestName
```

> NOTE: While the full suite runs in parallel, some of the tests can take up to a minute to complete

### Test Structure

This integration suite [uses a thin wrapper](https://godoc.org/github.com/cosmos/cosmos-sdk/tests) over the [`os/exec`](https://golang.org/pkg/os/exec/) package. This allows the integration test to run against built binaries (both `relayd` and `relaycli` are used) while being written in golang. This allows tests to take advantage of the various golang code we have for operations like marshal/unmarshal, crypto, etc...

> NOTE: The tests will use whatever `relayd` or `relaycli` binaries are available in your `$GOPATH/bin`. You can check which binary will be run by the suite by running `which relayd` or `which relaycli`. If you have your `$GOPATH` properly setup they should be in `$GOPATH/bin/relay*`. This will ensure that your test uses the latest binary you have built

Tests generally follow this structure:

```go
func (suite *UtilsSuite) TestMyNewCommand() {
suite.T().Parallel()
f := InitFixtures(suite.T())

// start relayd server
proc := f.GDStart()
defer proc.Stop(false)

// Your test code goes here...

f.Cleanup()
}
```

This boilerplate above:

- Ensures the tests run in parallel. Because the tests are calling out to `os/exec` for many operations these tests can take a long time to run.
- Creates `.relayd` and `.relaycli` folders in a new temp folder.
- Uses `relaycli` to create test account for use in testing: `foo`
- Creates a genesis file with coins (`1000footoken,1000feetoken,150stake`) controlled by the `foo` key
- Generates an initial bonding transaction (`gentx`) to make the `foo` key a validator at genesis
- Starts `relayd` and stops it once the test exits
- Cleans up test state on a successful run

### Notes when adding/running tests

- Because the tests run against a built binary, you should make sure you build every time the code changes and you want to test again, otherwise you will be testing against an older version. If you are adding new tests this can easily lead to confusing test results.
- The [`test_helpers.go`](./test_helpers.go) file is organized according to the format of `relaycli` and `relayd` commands. There are comments with section headers describing the different areas. Helper functions to call CLI functionality are generally named after the command (e.g. `relaycli query bestknowndigest` would be `QueryBestKnownDigest`). Try to keep functions grouped by their position in the command tree.
- Test state that is needed by `tx` and `query` commands (`home`, `chain_id`, etc...) is stored on the `Fixtures` object. This makes constructing your new tests almost trivial. Each test needs unique Fixture to run in parallel
- Sometimes if you exit a test early there can be still running `relayd` and `relaycli` processes that will interrupt subsequent runs. Still running `relayd` processes will block ports and prevent new tests from spinning up. You can ensure new tests spin up clean by running `pkill -9 relayd && pkill -9 relaycli` before each test run.
- Most `query` and `tx` commands take a variadic `flags` argument. This pattern allows for the creation of a general function which is easily modified by adding flags.
- `Tx*` functions follow a general pattern and return `(success bool, stdout string, stderr string)`. This allows for easy testing of multiple different flag configurations.
Loading