Skip to content

Commit bf81f8a

Browse files
author
Woosang Son
authored
test: enable sim test, race test (#326)
* test: enable race test * test: enable sim test * fix: implement MarshalJSONPB * fix: BaseAccount marshal/unmarshal * fix: remove param store cache, fix consensus param * fix: distribution key bug * fix: lint errors * fix: modify random param * test: disable cosmovisor test * fix: address conversion bug * docs: fix markdown check failures * test: fix action script of sim test * test: remove an env for private repo * test: fix action script typo * fix: apply comment * chore: fix lint error
1 parent 023dda2 commit bf81f8a

File tree

14 files changed

+268
-209
lines changed

14 files changed

+268
-209
lines changed

.github/workflows/sims.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
name: Sims
22
# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short)
33
# This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed
4-
env:
5-
GOPRIVATE: "github.com/line/*"
6-
7-
# TODO ebony: fix sim test failure
84
on:
9-
# pull_request:
10-
# push:
11-
# branches:
12-
# - main
5+
pull_request:
6+
push:
7+
branches:
8+
- main
139

1410
jobs:
1511
cleanup-runs:
@@ -62,6 +58,7 @@ jobs:
6258
with:
6359
PATTERNS: |
6460
**/**.go
61+
!**/**_test.go
6562
go.mod
6663
go.sum
6764
- uses: actions/[email protected]
@@ -86,8 +83,9 @@ jobs:
8683
run: go version
8784
- uses: technote-space/[email protected]
8885
with:
89-
SUFFIX_FILTER: |
86+
PATTERNS: |
9087
**/**.go
88+
!**/**_test.go
9189
go.mod
9290
go.sum
9391
SET_ENV_NAME_INSERTIONS: 1
@@ -114,8 +112,9 @@ jobs:
114112
run: go version
115113
- uses: technote-space/[email protected]
116114
with:
117-
SUFFIX_FILTER: |
115+
PATTERNS: |
118116
**/**.go
117+
!**/**_test.go
119118
go.mod
120119
go.sum
121120
SET_ENV_NAME_INSERTIONS: 1
@@ -142,8 +141,9 @@ jobs:
142141
run: go version
143142
- uses: technote-space/[email protected]
144143
with:
145-
SUFFIX_FILTER: |
144+
PATTERNS: |
146145
**/**.go
146+
!**/**_test.go
147147
go.mod
148148
go.sum
149149
SET_ENV_NAME_INSERTIONS: 1

.github/workflows/test.yml

+22-22
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,28 @@ jobs:
6565
- name: Build
6666
run: GOOS=linux CGO_ENABLED=1 GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} LEDGER_ENABLED=false make build
6767

68-
# TODO: disable test-race. please enable this after fixing concurrent checkTx
69-
# test-cosmovisor:
70-
# runs-on: ubuntu-latest
71-
# steps:
72-
# - uses: actions/checkout@v2
73-
# - uses: actions/[email protected]
74-
# with:
75-
# go-version: 1.15
76-
# - name: Display go version
77-
# run: go version
78-
# - uses: technote-space/[email protected]
79-
# id: git_diff
80-
# with:
81-
# PREFIX_FILTER: |
82-
# cosmovisor
83-
# PATTERNS: |
84-
# **/**.go
85-
# go.mod
86-
# go.sum
87-
# - name: Run cosmovisor tests
88-
# run: cd cosmovisor; make
89-
# if: env.GIT_DIFF
68+
# TODO: disable test-cosmovisor; this test uses uploaded binary(cosmos-sdk)
69+
# test-cosmovisor:
70+
# runs-on: ubuntu-latest
71+
# steps:
72+
# - uses: actions/checkout@v2
73+
# - uses: actions/[email protected]
74+
# with:
75+
# go-version: 1.15
76+
# - name: Display go version
77+
# run: go version
78+
# - uses: technote-space/[email protected]
79+
# id: git_diff
80+
# with:
81+
# PREFIX_FILTER: |
82+
# cosmovisor
83+
# PATTERNS: |
84+
# **/**.go
85+
# go.mod
86+
# go.sum
87+
# - name: Run cosmovisor tests
88+
# run: cd cosmovisor; make
89+
# if: env.GIT_DIFF
9090

9191
split-test-files:
9292
runs-on: ubuntu-latest

baseapp/baseapp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (app *BaseApp) setCheckState(header ocproto.Header) {
361361

362362
app.checkState = &state{
363363
ms: ms,
364-
ctx: ctx.WithConsensusParams(app.GetConsensusParams(ctx)),
364+
ctx: ctx,
365365
}
366366
}
367367

docs/core/proto-docs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ source tracing information path.
20702070
### FungibleTokenPacketData
20712071
FungibleTokenPacketData defines a struct for the packet payload
20722072
See FungibleTokenPacketData spec:
2073-
https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
2073+
https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures
20742074

20752075

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

24062406

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

24692469

24702470
| Field | Type | Label | Description |

x/auth/simulation/genesis.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func GenSigVerifyCostSECP256K1(r *rand.Rand) uint64 {
8989
}
9090

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

9596
// RandomizedGenState generates a random GenesisState for auth

x/auth/types/account.go

+34-33
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ var (
3131

3232
BaseAccountSig = []byte("bacc")
3333
ModuleAccountSig = []byte("macc")
34+
35+
PubKeyTypeSecp256k1 = byte(1)
36+
PubKeyTypeEd25519 = byte(2)
37+
PubKeyTypeMultisig = byte(3)
3438
)
3539

3640
// NewBaseAccount creates a new BaseAccount object
@@ -407,10 +411,14 @@ type GenesisAccount interface {
407411

408412
// custom json marshaler for BaseAccount & ModuleAccount
409413

414+
type PubKeyJSON struct {
415+
Type byte `json:"type"`
416+
Key []byte `json:"key"`
417+
}
410418
type BaseAccountJSON struct {
411-
Address string `json:"address"`
412-
PubKey json.RawMessage `json:"pub_key"`
413-
Sequence string `json:"sequence"`
419+
Address string `json:"address"`
420+
PubKey PubKeyJSON `json:"pub_key"`
421+
Sequence string `json:"sequence"`
414422
}
415423

416424
func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) {
@@ -420,19 +428,22 @@ func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) {
420428
bi.Sequence = strconv.FormatUint(acc.Sequence, 10)
421429
var bz []byte
422430
var err error
423-
if acc.Ed25519PubKey != nil {
424-
bz, err = codec.ProtoMarshalJSON(acc.Ed25519PubKey, m.AnyResolver)
425-
}
426431
if acc.Secp256K1PubKey != nil {
427-
bz, err = codec.ProtoMarshalJSON(acc.Secp256K1PubKey, m.AnyResolver)
432+
bi.PubKey.Type = PubKeyTypeSecp256k1
433+
bz, err = acc.Secp256K1PubKey.Marshal()
434+
}
435+
if acc.Ed25519PubKey != nil {
436+
bi.PubKey.Type = PubKeyTypeEd25519
437+
bz, err = acc.Ed25519PubKey.Marshal()
428438
}
429439
if acc.MultisigPubKey != nil {
430-
bz, err = codec.ProtoMarshalJSON(acc.MultisigPubKey, m.AnyResolver)
440+
bi.PubKey.Type = PubKeyTypeMultisig
441+
bz, err = acc.MultisigPubKey.Marshal()
431442
}
432443
if err != nil {
433444
return nil, err
434445
}
435-
bi.PubKey = bz
446+
bi.PubKey.Key = bz
436447
return json.Marshal(bi)
437448
}
438449

@@ -443,42 +454,32 @@ func (acc *BaseAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error
443454
if err != nil {
444455
return err
445456
}
446-
/* TODO: do we need to validate address format here
447-
err = sdk.ValidateAccAddress(bi.Address)
448-
if err != nil {
449-
return err
450-
}
451-
*/
452457

453458
acc.Address = bi.Address
454459
acc.Sequence, err = strconv.ParseUint(bi.Sequence, 10, 64)
455460
if err != nil {
456461
return err
457462
}
458463

459-
done := false
460-
if !done {
464+
switch bi.PubKey.Type {
465+
case PubKeyTypeSecp256k1:
461466
pk := new(secp256k1.PubKey)
462-
any, _ := codectypes.NewAnyWithValue(pk)
463-
if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil {
464-
acc.SetPubKey(pk)
465-
done = true
467+
if err := pk.Unmarshal(bi.PubKey.Key); err != nil {
468+
return err
466469
}
467-
}
468-
if !done {
469-
pk := new(ed25519.PubKey)
470-
any, _ := codectypes.NewAnyWithValue(pk)
471-
if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil {
472-
acc.SetPubKey(pk)
473-
done = true
470+
acc.SetPubKey(pk)
471+
case PubKeyTypeEd25519:
472+
pk := new(secp256k1.PubKey)
473+
if err := pk.Unmarshal(bi.PubKey.Key); err != nil {
474+
return err
474475
}
475-
}
476-
if !done {
476+
acc.SetPubKey(pk)
477+
case PubKeyTypeMultisig:
477478
pk := new(multisig.LegacyAminoPubKey)
478-
any, _ := codectypes.NewAnyWithValue(pk)
479-
if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil {
480-
acc.SetPubKey(pk)
479+
if err := pk.Unmarshal(bi.PubKey.Key); err != nil {
480+
return err
481481
}
482+
acc.SetPubKey(pk)
482483
}
483484
return nil
484485
}

x/auth/types/account_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"testing"
88

9+
"github.com/line/lbm-sdk/codec"
10+
types2 "github.com/line/lbm-sdk/codec/types"
911
"github.com/stretchr/testify/require"
1012
yaml "gopkg.in/yaml.v2"
1113

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

53+
func TestBaseAccountMarshalUnmarshalJSON(t *testing.T) {
54+
interfaceRegistry := types2.NewInterfaceRegistry()
55+
56+
cdc := codec.NewProtoCodec(interfaceRegistry)
57+
_, pub, addr := testdata.KeyTestPubAddr()
58+
acc := types.NewBaseAccountWithAddress(addr)
59+
acc.SetPubKey(pub)
60+
61+
bz := cdc.MustMarshalJSON(acc)
62+
var acc2 types.BaseAccount
63+
64+
cdc.MustUnmarshalJSON(bz, &acc2)
65+
require.Equal(t, acc, &acc2)
66+
}
67+
5168
func TestBaseSequence(t *testing.T) {
5269
_, _, addr := testdata.KeyTestPubAddr()
5370
acc := types.NewBaseAccountWithAddress(addr)

0 commit comments

Comments
 (0)