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
9 changes: 4 additions & 5 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ name: Sims
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
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/setup-go@v2.1.4
# with:
# go-version: 1.15
# - name: Display go version
# run: go version
# - uses: technote-space/get-diff-action@v5.0.1
# 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/setup-go@v2.1.4
# with:
# go-version: 1.15
# - name: Display go version
# run: go version
# - uses: technote-space/get-diff-action@v5.0.1
# 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
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
62 changes: 30 additions & 32 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 @@ -408,9 +412,10 @@ type GenesisAccount interface {
// custom json marshaler for BaseAccount & ModuleAccount

type BaseAccountJSON struct {
Address string `json:"address"`
PubKey json.RawMessage `json:"pub_key"`
Sequence string `json:"sequence"`
Address string `json:"address"`
PubType byte `json:"pub_type"`
PubKey []byte `json:"pub_key"`
Copy link
Contributor

Choose a reason for hiding this comment

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

How about grouping the pubkey properties?

e.g.

{
  "address": ...,
  "sequence": ...,
  "pub_key": {
    "type":...,
    "key":...,
  }
}

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I apply it.

Sequence string `json:"sequence"`
}

func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) {
Expand All @@ -420,14 +425,17 @@ 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.PubType = PubKeyTypeSecp256k1
bz, err = acc.Secp256K1PubKey.Marshal()
}
if acc.Ed25519PubKey != nil {
bi.PubType = PubKeyTypeEd25519
bz, err = acc.Ed25519PubKey.Marshal()
}
if acc.MultisigPubKey != nil {
bz, err = codec.ProtoMarshalJSON(acc.MultisigPubKey, m.AnyResolver)
bi.PubType = PubKeyTypeMultisig
bz, err = acc.MultisigPubKey.Marshal()
}
if err != nil {
return nil, err
Expand All @@ -443,42 +451,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.PubType {
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); 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); 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); 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