Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jan 17, 2023
1 parent df9bf88 commit cc048bc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
5 changes: 4 additions & 1 deletion pkg/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
}

isIndexedValue := func(b uint8) bool {
return b&types.EventFlagIndexedValue == types.EventFlagIndexedValue
// currently we mark the full entry as indexed if either the key
// or the value are indexed; in the future we will need finer-grained
// management of indices
return b&(types.EventFlagIndexedKey|types.EventFlagIndexedValue) > 0
}

for msgIdx, em := range ems {
Expand Down
7 changes: 7 additions & 0 deletions pkg/wallet/key/keyinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"testing"

Expand All @@ -20,6 +21,12 @@ import (
"github.com/filecoin-project/venus/pkg/crypto"
)

// copy from `github.com/filecoin-project/venus/pkg/testhelpers/testflags`,avoid `import cycle not allowed`
var (
integrationTest = flag.Bool("integration", true, "Run the integration go tests") // nolint
unitTest = flag.Bool("unit", true, "Run the unit go tests") // nolint
)

func TestKeyInfoAddress(t *testing.T) {
prv, _ := hex.DecodeString("2a2a2a2a2a2a2a2a5fbf0ed0f8364c01ff27540ecd6669ff4cc548cbe60ef5ab")
ki := &KeyInfo{
Expand Down
1 change: 1 addition & 0 deletions venus-shared/types/eth_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
crypto1 "github.com/filecoin-project/go-state-types/crypto"

"github.com/filecoin-project/venus/pkg/crypto"
_ "github.com/filecoin-project/venus/pkg/crypto/delegated"
"github.com/filecoin-project/venus/venus-shared/actors"
)

Expand Down
6 changes: 3 additions & 3 deletions venus-shared/types/rlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
// maxListElements restricts the amount of RLP list elements we'll read.
// The ETH API only ever reads EIP-1559 transactions, which are bounded by
// 12 elements exactly, so we play it safe and set exactly that limit here.
const maxListElements = 500
const maxListElements = 12

func EncodeRLP(val interface{}) ([]byte, error) {
return encodeRLP(val)
}

func encodeRLPListItems(list []interface{}) (result []byte, err error) {
var res []byte
res := []byte{}
for _, elem := range list {
encoded, err := encodeRLP(elem)
if err != nil {
Expand Down Expand Up @@ -163,7 +163,7 @@ func decodeLength(data []byte, lenInBytes int) (length int, err error) {

func decodeListElems(data []byte, length int) (res []interface{}, err error) {
totalConsumed := 0
var result []interface{}
result := []interface{}{}

for i := 0; totalConsumed < length && i < maxListElements; i++ {
elem, consumed, err := decodeRLP(data[totalConsumed:])
Expand Down
38 changes: 32 additions & 6 deletions venus-shared/utils/method_map_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package utils

import (
"fmt"
"testing"

actortypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/manifest"
tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/types"
"github.com/ipfs/go-cid"
"github.com/stretchr/testify/assert"
)

Expand All @@ -15,9 +19,8 @@ func TestMethodMap(t *testing.T) {
t.Run("Default to load mainnet actors", func(t *testing.T) {
for _, actorsMetadata := range actors.EmbeddedBuiltinActorsMetadata {
if actorsMetadata.Network == string(types.NetworkNameMain) {
for _, actor := range actorsMetadata.Actors {
_, ok := MethodsMap[actor]
assert.True(t, ok)
for name, actor := range actorsMetadata.Actors {
checkActorCode(t, actorsMetadata.Version, actor, name, actorsMetadata.Network)
}
}
}
Expand All @@ -28,11 +31,34 @@ func TestMethodMap(t *testing.T) {
ReloadMethodsMap()
for _, actorsMetadata := range actors.EmbeddedBuiltinActorsMetadata {
if actorsMetadata.Network == string(types.NetworkNameButterfly) {
for _, actor := range actorsMetadata.Actors {
_, ok := MethodsMap[actor]
assert.True(t, ok)
for name, actor := range actorsMetadata.Actors {
checkActorCode(t, actorsMetadata.Version, actor, name, actorsMetadata.Network)
}
}
}
})
}

func checkActorCode(t *testing.T, actorVersion actortypes.Version, actorCode cid.Cid, actorName, networkName string) {
actorKeysWithVersion := map[string]actortypes.Version{
manifest.EamKey: actortypes.Version10,
manifest.EvmKey: actortypes.Version10,
manifest.PlaceholderKey: actortypes.Version10,
manifest.EthAccountKey: actortypes.Version10,
}

ver, ok := actorKeysWithVersion[actorName]
if ok {
if actorVersion < ver {
return
}
}

_, ok = MethodsMap[actorCode]
comment := fmt.Sprintf("actor %s not found: %s %d %s", actorCode, networkName, actorVersion, actorName)
assert.Truef(t, ok, comment)

res, ok := actors.GetActorCodeID(actorVersion, actorName)
assert.Truef(t, ok, comment)
assert.Equalf(t, actorCode, res, "actor not found: name %s expect %s, actual %s", actorName, actorCode, res)
}
12 changes: 5 additions & 7 deletions venus-shared/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@ func TestLoadBuiltinActors(t *testing.T) {
full := mock.NewMockFullNode(ctrl)

for nn := range NetworkNameWithNetworkType {
full.EXPECT().StateNetworkName(ctx).Return(nn, nil)
if nn == types.NetworkNameWallaby || nn == types.NetworkNameHyperspace {
continue
}

full.EXPECT().StateNetworkName(ctx).Return(nn, nil)
assert.Nil(t, LoadBuiltinActors(ctx, full))

for _, actorsMetadata := range actors.EmbeddedBuiltinActorsMetadata {
if actorsMetadata.Network == string(nn) {
for name, actor := range actorsMetadata.Actors {
res, ok := actors.GetActorCodeID(actorsMetadata.Version, name)
assert.True(t, ok)
assert.Equal(t, actor, res)

_, ok2 := MethodsMap[actor]
assert.True(t, ok2)
checkActorCode(t, actorsMetadata.Version, actor, name, actorsMetadata.Network)
}
}
}
Expand Down

0 comments on commit cc048bc

Please sign in to comment.