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

test: enable sim test, race test #326

Merged
merged 16 commits into from
Sep 27, 2021
22 changes: 11 additions & 11 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
name: Sims
# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short)
# This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed
env:
GOPRIVATE: "github.com/line/*"

# TODO ebony: fix sim test failure
on:
# pull_request:
# push:
# branches:
# - main
pull_request:
push:
branches:
- main

jobs:
cleanup-runs:
Expand Down Expand Up @@ -62,6 +58,7 @@ jobs:
with:
PATTERNS: |
**/**.go
!**/**_test.go
go.mod
go.sum
- uses: actions/[email protected]
Expand All @@ -86,8 +83,9 @@ jobs:
run: go version
- uses: technote-space/[email protected]
with:
SUFFIX_FILTER: |
PATTERNS: |
**/**.go
!**/**_test.go
go.mod
go.sum
SET_ENV_NAME_INSERTIONS: 1
Expand All @@ -114,8 +112,9 @@ jobs:
run: go version
- uses: technote-space/[email protected]
with:
SUFFIX_FILTER: |
PATTERNS: |
**/**.go
!**/**_test.go
go.mod
go.sum
SET_ENV_NAME_INSERTIONS: 1
Expand All @@ -142,8 +141,9 @@ jobs:
run: go version
- uses: technote-space/[email protected]
with:
SUFFIX_FILTER: |
PATTERNS: |
**/**.go
!**/**_test.go
go.mod
go.sum
SET_ENV_NAME_INSERTIONS: 1
Expand Down
44 changes: 22 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ jobs:
- name: Build
run: GOOS=linux CGO_ENABLED=1 GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} LEDGER_ENABLED=false make build

# TODO: disable test-race. please enable this after fixing concurrent checkTx
# test-cosmovisor:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.15
# - name: Display go version
# run: go version
# - uses: technote-space/[email protected]
# id: git_diff
# with:
# PREFIX_FILTER: |
# cosmovisor
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - name: Run cosmovisor tests
# run: cd cosmovisor; make
# if: env.GIT_DIFF
# TODO: disable test-cosmovisor; this test uses uploaded binary(cosmos-sdk)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to enable this, research on test-cosmovisor is needed. We have to do this as a separate task.

# test-cosmovisor:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.15
# - name: Display go version
# run: go version
# - uses: technote-space/[email protected]
# id: git_diff
# with:
# PREFIX_FILTER: |
# cosmovisor
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - name: Run cosmovisor tests
# run: cd cosmovisor; make
# if: env.GIT_DIFF

split-test-files:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (app *BaseApp) setCheckState(header ocproto.Header) {

app.checkState = &state{
ms: ms,
ctx: ctx.WithConsensusParams(app.GetConsensusParams(ctx)),
ctx: ctx,
Copy link
Author

@egonspace egonspace Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification reverts a part of #142.
The previous code causes sim test failure.
We must not call app.GetConsensusParams() while we initialize checkState because app.GetConsensusParams() caches nil value in cache store.
Normally, this is not a problem, but this is a problem because simulation tests do deliverTx immediately without checkTx.

}
}

Expand Down
6 changes: 3 additions & 3 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ source tracing information path.
### FungibleTokenPacketData
FungibleTokenPacketData defines a struct for the packet payload
See FungibleTokenPacketData spec:
https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures


| Field | Type | Label | Description |
Expand Down Expand Up @@ -2401,7 +2401,7 @@ Params defines the set of IBC light client parameters.
### MsgTransfer
MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between
ICS20 enabled chains. See ICS Spec here:
https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
https://github.com/cosmos/ics/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures


| Field | Type | Label | Description |
Expand Down Expand Up @@ -2464,7 +2464,7 @@ NOTE: The field numbers 21 and 22 were explicitly chosen to avoid accidental
conflicts with other protobuf message formats used for acknowledgements.
The first byte of any message with this format will be the non-ASCII values
`0xaa` (result) or `0xb2` (error). Implemented as defined by ICS:
https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope
https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#acknowledgement-envelope


| Field | Type | Label | Description |
Expand Down
3 changes: 2 additions & 1 deletion x/auth/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func GenSigVerifyCostSECP256K1(r *rand.Rand) uint64 {
}

func GenValidSigBlockPeriod(r *rand.Rand) uint64 {
return uint64(simulation.RandIntBetween(r, 1, 1000))
// We use valid sig block period greater than 100 for testing
return uint64(simulation.RandIntBetween(r, 100, 1000))
}

// RandomizedGenState generates a random GenesisState for auth
Expand Down
67 changes: 34 additions & 33 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var (

BaseAccountSig = []byte("bacc")
ModuleAccountSig = []byte("macc")

PubKeyTypeSecp256k1 = byte(1)
PubKeyTypeEd25519 = byte(2)
PubKeyTypeMultisig = byte(3)
)

// NewBaseAccount creates a new BaseAccount object
Expand Down Expand Up @@ -407,10 +411,14 @@ type GenesisAccount interface {

// custom json marshaler for BaseAccount & ModuleAccount

type PubKeyJSON struct {
Type byte `json:"type"`
Key []byte `json:"key"`
}
type BaseAccountJSON struct {
Address string `json:"address"`
PubKey json.RawMessage `json:"pub_key"`
Sequence string `json:"sequence"`
Address string `json:"address"`
PubKey PubKeyJSON `json:"pub_key"`
Sequence string `json:"sequence"`
}

func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) {
Expand All @@ -420,19 +428,22 @@ func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) {
bi.Sequence = strconv.FormatUint(acc.Sequence, 10)
var bz []byte
var err error
if acc.Ed25519PubKey != nil {
bz, err = codec.ProtoMarshalJSON(acc.Ed25519PubKey, m.AnyResolver)
}
if acc.Secp256K1PubKey != nil {
bz, err = codec.ProtoMarshalJSON(acc.Secp256K1PubKey, m.AnyResolver)
bi.PubKey.Type = PubKeyTypeSecp256k1
bz, err = acc.Secp256K1PubKey.Marshal()
}
if acc.Ed25519PubKey != nil {
bi.PubKey.Type = PubKeyTypeEd25519
bz, err = acc.Ed25519PubKey.Marshal()
}
if acc.MultisigPubKey != nil {
bz, err = codec.ProtoMarshalJSON(acc.MultisigPubKey, m.AnyResolver)
bi.PubKey.Type = PubKeyTypeMultisig
bz, err = acc.MultisigPubKey.Marshal()
}
if err != nil {
return nil, err
}
bi.PubKey = bz
bi.PubKey.Key = bz
return json.Marshal(bi)
}

Expand All @@ -443,42 +454,32 @@ func (acc *BaseAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error
if err != nil {
return err
}
/* TODO: do we need to validate address format here
err = sdk.ValidateAccAddress(bi.Address)
if err != nil {
return err
}
*/

acc.Address = bi.Address
acc.Sequence, err = strconv.ParseUint(bi.Sequence, 10, 64)
if err != nil {
return err
}

done := false
if !done {
switch bi.PubKey.Type {
case PubKeyTypeSecp256k1:
pk := new(secp256k1.PubKey)
any, _ := codectypes.NewAnyWithValue(pk)
if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil {
acc.SetPubKey(pk)
done = true
if err := pk.Unmarshal(bi.PubKey.Key); err != nil {
return err
}
}
if !done {
pk := new(ed25519.PubKey)
any, _ := codectypes.NewAnyWithValue(pk)
if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil {
acc.SetPubKey(pk)
done = true
acc.SetPubKey(pk)
case PubKeyTypeEd25519:
pk := new(secp256k1.PubKey)
if err := pk.Unmarshal(bi.PubKey.Key); err != nil {
return err
}
}
if !done {
acc.SetPubKey(pk)
case PubKeyTypeMultisig:
pk := new(multisig.LegacyAminoPubKey)
any, _ := codectypes.NewAnyWithValue(pk)
if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil {
acc.SetPubKey(pk)
if err := pk.Unmarshal(bi.PubKey.Key); err != nil {
return err
}
acc.SetPubKey(pk)
}
return nil
}
Expand Down
17 changes: 17 additions & 0 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"testing"

"github.com/line/lbm-sdk/codec"
types2 "github.com/line/lbm-sdk/codec/types"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2"

Expand Down Expand Up @@ -48,6 +50,21 @@ func TestBaseAddressPubKey(t *testing.T) {
require.EqualValues(t, addr2, acc2.GetAddress())
}

func TestBaseAccountMarshalUnmarshalJSON(t *testing.T) {
interfaceRegistry := types2.NewInterfaceRegistry()

cdc := codec.NewProtoCodec(interfaceRegistry)
_, pub, addr := testdata.KeyTestPubAddr()
acc := types.NewBaseAccountWithAddress(addr)
acc.SetPubKey(pub)

bz := cdc.MustMarshalJSON(acc)
var acc2 types.BaseAccount

cdc.MustUnmarshalJSON(bz, &acc2)
require.Equal(t, acc, &acc2)
}

func TestBaseSequence(t *testing.T) {
_, _, addr := testdata.KeyTestPubAddr()
acc := types.NewBaseAccountWithAddress(addr)
Expand Down
Loading