Skip to content

Commit

Permalink
Merge pull request #111 from terra-money/fix/ci
Browse files Browse the repository at this point in the history
fix: ci on cosmossdk 46
  • Loading branch information
javiersuweijie authored Mar 17, 2023
2 parents 1242fea + 6bc3c34 commit 031bb60
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 117 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: 1.20.0
- run: go build ./...

test:
runs-on: ubuntu-latest
name: test
steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: 1.20.0
- name: Checkout code
uses: actions/checkout@v3
- name: Test
Expand All @@ -34,9 +34,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: 1.20.0
- run: |
go mod tidy
CHANGES_IN_REPO=$(git status --porcelain)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: 1.20.0
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
test-coverage-upload:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: 1.20.0
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.18.2-alpine3.15 AS go-builder
FROM golang:1.20-alpine3.17 AS go-builder
#ARG arch=x86_64

# See https://github.com/terra-money/wasmvm/releases
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ clean-testing-data:
@echo "Killing terrad and removing previous data"
-@rm -rf ./data
-@killall terrad 2>/dev/null
-@killall rly 2>/dev/null

.PHONY: integration-test-all init-test-framework test-relayer test-ica test-ibc-hooks test-vesting-accounts test-tokenfactory clean-testing-data

Expand Down
88 changes: 36 additions & 52 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"

ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v6/modules/core"
"github.com/cosmos/ibc-go/v6/testing/mock"
"github.com/strangelove-ventures/packet-forward-middleware/v6/router"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/CosmWasm/wasmd/x/wasm"
)
Expand Down Expand Up @@ -73,7 +72,24 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, encCfg,
simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())

genesisState := NewDefaultGenesisState(encCfg.Marshaler)
// generate validator private/public key
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(),
}

genesisState := SetupGenesisValSet(valSet, []authtypes.GenesisAccount{acc}, nil, app, encCfg, balance)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

Expand All @@ -93,9 +109,6 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
_, err = app2.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")

_, err = app2.ExportAppStateAndValidators(true, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

func TestGetMaccPerms(t *testing.T) {
Expand Down Expand Up @@ -155,34 +168,6 @@ func TestInitGenesisOnMigration(t *testing.T) {
require.NoError(t, err)
}

func TestUpgradeStateOnGenesis(t *testing.T) {
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0,
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())

genesisState := NewDefaultGenesisState(encCfg.Marshaler)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)

// make sure the upgrade keeper has version map in state
ctx := app.NewContext(false, tmproto.Header{})
vm := app.UpgradeKeeper.GetModuleVersionMap(ctx)
for v, i := range app.mm.Modules {
require.Equal(t, vm[v], i.ConsensusVersion())
}
}

func TestLegacyAmino(t *testing.T) {
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
Expand Down Expand Up @@ -230,6 +215,13 @@ func TestGetKey(t *testing.T) {
}

func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, encCfg,
simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig(),
)
genAccounts := authtypes.GenesisAccounts{
vestingtypes.NewContinuousVestingAccount(
authtypes.NewBaseAccountWithAddress(addr1),
Expand All @@ -246,7 +238,7 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
authtypes.NewBaseAccountWithAddress(addr3),
authtypes.NewBaseAccountWithAddress(addr4),
}
app := SetupWithGenesisAccounts(genAccounts, []banktypes.Balance{
balances := []banktypes.Balance{
{
Address: addr1.String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(2_500_000_000_000))),
Expand All @@ -263,26 +255,18 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
Address: addr4.String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1_000_000))),
},
}...)
}

// generate validator private/public key
privVal := mock.NewPV()
pubKey, _ := privVal.GetPubKey()
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

genesisState := SetupGenesisValSet(valSet, genAccounts, nil, app, encCfg, balances...)
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

genesisState := make(GenesisState)
genesisState[authtypes.ModuleName] = app.appCodec.MustMarshalJSON(authtypes.NewGenesisState(authtypes.DefaultParams(), genAccounts))

tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

// create validator with 10% commission
pubkeys := simapp.CreateTestPubKeys(2)
valAddrs := simapp.ConvertAddrsToValAddrs([]sdk.AccAddress{addr3, addr4})
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(2, 1), sdk.NewDec(0))
tstaking.CreateValidator(sdk.ValAddress(addr3), pubkeys[0], sdk.NewInt(1_000_000), true)
tstaking.CreateValidator(sdk.ValAddress(addr4), pubkeys[1], sdk.NewInt(1_000_000), true)
vals := []stakingtypes.ValidatorI{app.StakingKeeper.Validator(ctx, valAddrs[0]), app.StakingKeeper.Validator(ctx, valAddrs[1])}
require.NotNil(t, vals[0])
require.NotNil(t, vals[1])

app.enforceStakingForVestingTokens(ctx, genesisState)
delegations := app.StakingKeeper.GetAllDelegations(ctx)
sharePerValidators := make(map[string]sdk.Dec)

Expand Down
107 changes: 56 additions & 51 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,78 @@ package app
// DONTCOVER

import (
"encoding/json"
"time"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
"github.com/terra-money/core/v2/app/wasmconfig"
"github.com/CosmWasm/wasmd/x/wasm"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"

"github.com/cosmos/cosmos-sdk/simapp"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
tmtypes "github.com/tendermint/tendermint/types"
terrraParams "github.com/terra-money/core/v2/app/params"
)

func setup(withGenesis bool, invCheckPeriod uint) (*TerraApp, GenesisState) {
db := dbm.NewMemDB()
encCdc := MakeEncodingConfig()
app := NewTerraApp(
log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
simapp.DefaultNodeHome,
invCheckPeriod,
encCdc,
simapp.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)
func SetupGenesisValSet(
valSet *tmtypes.ValidatorSet,
genAccs []authtypes.GenesisAccount,
opts []wasm.Option,
app *TerraApp,
encCfg terrraParams.EncodingConfig,
balances ...banktypes.Balance,
) GenesisState {
genesisState := NewDefaultGenesisState(encCfg.Marshaler)
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.appCodec.MustMarshalJSON(authGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.NewInt(1000000)
totalSupply := sdk.NewCoins()

for _, val := range valSet.Validators {
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))

if withGenesis {
return app, NewDefaultGenesisState(encCdc.Marshaler)
}

return app, GenesisState{}
}
// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
genesisState[stakingtypes.ModuleName] = app.appCodec.MustMarshalJSON(stakingGenesis)

// SetupWithGenesisAccounts setup TerraApp with genesis account
func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *TerraApp {
app, genesisState := setup(true, 0)
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)},
})

totalSupply := sdk.NewCoins()
for _, b := range balances {
// add genesis acc tokens and delegated tokens to total supply
totalSupply = totalSupply.Add(b.Coins...)
}

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}

app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simapp.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)

app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}})
genesisState[banktypes.ModuleName] = app.appCodec.MustMarshalJSON(bankGenesis)

return app
return genesisState
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ require (
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
Expand Down
Loading

0 comments on commit 031bb60

Please sign in to comment.