diff --git a/.golangci.yml b/.golangci.yml index fc3cbcd2b..b555b6edf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -66,7 +66,6 @@ linters-settings: # Available rules: https://github.com/securego/gosec#available-rules # Default: [] - means include all rules includes: - # - G101 # Look for hard coded credentials - G102 # Bind to all interfaces - G103 # Audit the use of unsafe block - G104 # Audit errors not checked diff --git a/Makefile b/Makefile index 9d9652dde..1393898a5 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true BINDIR ?= $(GOPATH)/bin +MOCKS_DIR = $(CURDIR)/tests/mocks APP = ./app DOCKER := $(shell which docker) @@ -59,6 +60,10 @@ release: go.sum env GOOS=windows GOARCH=amd64 \ go build -mod=readonly -o ./build/yoda_windows_amd64 $(BUILD_FLAGS) ./cmd/yoda +mocks: + @go install go.uber.org/mock/mockgen@latest + sh ./scripts/mockgen.sh + go.sum: go.mod @echo "--> Ensure dependencies have not been modified" GO111MODULE=on go mod verify @@ -115,5 +120,5 @@ test-sim-deterministic: runsim @echo "Running application deterministic simulation. This may take awhile!" @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(APP) -ExitOnFail 1 1 TestAppStateDeterminism -.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking \ +.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking mocks \ test-sim-import-export test-sim-multi-seed-short test-sim-after-import test-sim-deterministic diff --git a/benchmark/app_test.go b/benchmark/app_test.go index e254c9971..e293298c1 100644 --- a/benchmark/app_test.go +++ b/benchmark/app_test.go @@ -43,7 +43,7 @@ func InitializeBenchmarkApp(tb testing.TB, maxGasPerBlock int64) *BenchmarkApp { }, TB: tb, } - ba.Ctx = ba.NewUncachedContext(false, tmproto.Header{}) + ba.Ctx = ba.NewUncachedContext(false, tmproto.Header{ChainID: bandtesting.ChainID}) ba.Querier = keeper.Querier{ Keeper: ba.OracleKeeper, } @@ -91,8 +91,11 @@ func (ba *BenchmarkApp) DeliverMsg(account *Account, msgs []sdk.Msg) (sdk.GasInf func (ba *BenchmarkApp) CallBeginBlock() abci.ResponseBeginBlock { return ba.BeginBlock( abci.RequestBeginBlock{ - Header: tmproto.Header{Height: ba.LastBlockHeight() + 1}, - Hash: ba.LastCommitID().Hash, + Header: tmproto.Header{ + Height: ba.LastBlockHeight() + 1, + ChainID: bandtesting.ChainID, + }, + Hash: ba.LastCommitID().Hash, }, ) } diff --git a/benchmark/helper_test.go b/benchmark/helper_test.go index 242239246..5954f8a1a 100644 --- a/benchmark/helper_test.go +++ b/benchmark/helper_test.go @@ -133,7 +133,7 @@ func GenSequenceOfTxs( msgs, sdk.Coins{sdk.NewInt64Coin("uband", 1)}, math.MaxInt64, - "", + bandtesting.ChainID, []uint64{account.Num}, []uint64{account.Seq}, account.PrivKey, diff --git a/scripts/generate_genesis.sh b/scripts/generate_genesis.sh index 88ec52003..500dab24f 100755 --- a/scripts/generate_genesis.sh +++ b/scripts/generate_genesis.sh @@ -8,11 +8,16 @@ echo "lock nasty suffer dirt dream fine fall deal curtain plate husband sound to | bandd keys add validator --recover --keyring-backend test echo "smile stem oven genius cave resource better lunar nasty moon company ridge brass rather supply used horn three panic put venue analyst leader comic" \ | bandd keys add requester --recover --keyring-backend test - +echo "erase relief tree tobacco around knee concert toast diesel melody rule sight forum camera oil sick leopard valid furnace casino post dumb tag young" \ + | bandd keys add account1 --recover --keyring-backend test +echo "thought insane behind cool expand clarify strategy occur arrive broccoli middle despair foot cake genuine dawn goose abuse curve identify dinner derive genre effort" \ + | bandd keys add account2 --recover --keyring-backend test # add accounts to genesis bandd genesis add-genesis-account validator 10000000000000uband --keyring-backend test bandd genesis add-genesis-account requester 10000000000000uband --keyring-backend test +bandd genesis add-genesis-account account1 10000000000000uband --keyring-backend test +bandd genesis add-genesis-account account2 10000000000000uband --keyring-backend test # register initial validators @@ -34,3 +39,6 @@ sed -i -e \ sed -i -e \ '/\[mempool\]/,+10 s/version = .*/version = \"v1\"/' \ ~/.band/config/config.toml + +# update voting period to be 60s for testing +cat <<< $(jq '.app_state.gov.params.voting_period = "60s"' ~/.band/config/genesis.json) > ~/.band/config/genesis.json diff --git a/scripts/group/create_group.sh b/scripts/group/create_group.sh new file mode 100755 index 000000000..78d3d8ecd --- /dev/null +++ b/scripts/group/create_group.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +export WALLET_NAME=account1 +export ENDPOINT=http://localhost:26657 + +BASEDIR=$(dirname "$0") + +TX_HASH=$(bandd tx group create-group $(bandd keys show $WALLET_NAME --address --keyring-backend test) "ipfs://" $BASEDIR/group_members.json \ + --from $WALLET_NAME \ + --node $ENDPOINT \ + -y --keyring-backend test --gas-prices 0.0025uband -b sync --output json | jq '.txhash'| tr -d '"') +echo "TX_HASH: $TX_HASH" + +sleep 3 + +GROUP_ID=$(bandd query tx $TX_HASH --node $ENDPOINT --output json | jq '.events' | jq -r '.[] | select(.type == "cosmos.group.v1.EventCreateGroup") | .attributes[0].value' | jq -r '.') +echo "GROUP_ID: $GROUP_ID" + diff --git a/scripts/group/create_policy.sh b/scripts/group/create_policy.sh new file mode 100755 index 000000000..88c58489a --- /dev/null +++ b/scripts/group/create_policy.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +export WALLET_NAME=account1 +export GROUP_ID=1 +export ENDPOINT=http://localhost:26657 + +BASEDIR=$(dirname "$0") + +TX_HASH=$(bandd tx group create-group-policy $(bandd keys show $WALLET_NAME --address --keyring-backend test) $GROUP_ID "{\"name\":\"policy 1\",\"description\":\"\"}" $BASEDIR/threshold_policy.json \ + --from $WALLET_NAME \ + --node $ENDPOINT \ + -y --keyring-backend test --gas-prices 0.0025uband -b sync --output json | jq '.txhash'| tr -d '"') +echo "TX_HASH: $TX_HASH" + +sleep 3 + +GROUP_POLICY_ADDRESS=$(bandd query tx $TX_HASH --node $ENDPOINT --output json | jq '.events' | jq -r '.[] | select(.type == "cosmos.group.v1.EventCreateGroupPolicy") | .attributes[0].value' | jq -r '.') +echo "GROUP_POLICY_ADDRESS: $GROUP_POLICY_ADDRESS" diff --git a/scripts/group/group_members.json b/scripts/group/group_members.json new file mode 100644 index 000000000..9b8b15560 --- /dev/null +++ b/scripts/group/group_members.json @@ -0,0 +1,14 @@ +{ + "members": [ + { + "address": "band1w8yurh6naeqg4mjx4zcs7hsu3fppwu0f4q4l7f", + "weight": "1", + "metadata": "account1" + }, + { + "address": "band1ph8tcg7ncxxx5vndfc9h6ffsn4st4whq3rn260", + "weight": "1", + "metadata": "account2" + } + ] +} diff --git a/scripts/group/threshold_policy.json b/scripts/group/threshold_policy.json new file mode 100644 index 000000000..570c10ecb --- /dev/null +++ b/scripts/group/threshold_policy.json @@ -0,0 +1,8 @@ +{ + "@type": "/cosmos.group.v1.ThresholdDecisionPolicy", + "threshold": "2", + "windows": { + "voting_period": "1m", + "min_execution_period": "0s" + } +} diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh new file mode 100755 index 000000000..381a18e51 --- /dev/null +++ b/scripts/mockgen.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +mockgen_cmd="mockgen"