Skip to content

Commit

Permalink
fix: codec
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 5, 2024
1 parent 37288d6 commit e72e976
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
22 changes: 17 additions & 5 deletions e2e/helpers/action_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ func ExecuteExec(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, i

// If the codec can not properly unmarshal, then it may be a standard json Unmarshal request.
// This is required since we are ExecuteExec'ing an interface{} instead of some concrete type.
err = chain.GetCodec().UnmarshalInterface(stdout, &i)
if err != nil && !strings.Contains(err.Error(), "illegal wireType") {
fmt.Println("chain.GetCodec.UnmarshalInterface", err)
cdc := chain.GetCodec()
if cdc != nil {
err = cdc.UnmarshalInterface(stdout, &i)
if err != nil && !strings.Contains(err.Error(), "illegal wireType") {
fmt.Println("chain.GetCodec.UnmarshalInterface", err)
}
}
}

Expand All @@ -65,8 +68,17 @@ func ExecuteTransaction(ctx context.Context, chain *cosmos.CosmosChain, cmd []st
}

var res sdk.TxResponse
if err := chain.GetCodec().UnmarshalJSON(stdout, &res); err != nil {
return sdk.TxResponse{}, err

cdc := chain.GetCodec()

if cdc != nil {
if err := cdc.UnmarshalJSON(stdout, &res); err != nil {
// return sdk.TxResponse{}, fmt.Errorf("failed to cdc unmarshal tx response: %s", err)
fmt.Println("cdc.UnmarshalJSON err", err, "using json Unmarshal instead")
json.Unmarshal(stdout, &res)
}
} else {
json.Unmarshal(stdout, &res)
}

return res, err
Expand Down
8 changes: 6 additions & 2 deletions e2e/poa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"os"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -34,6 +35,8 @@ func TestPOABase(t *testing.T) {
t.Fatal(err)
}

require.NoError(t, os.Setenv("POA_BYPASS_ADMIN_CHECK_FOR_SIMULATION_TESTING_ONLY", "false"))

users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain)
incorrectUser := users[0]

Expand Down Expand Up @@ -120,8 +123,9 @@ func testPowerErrors(t *testing.T, ctx context.Context, chain *cosmos.CosmosChai
var err error

t.Run("fail: set-power message from a non authorized user", func(t *testing.T) {
// runtime error: index out of range [1] with length 1 [recovered]
res, _ = helpers.POASetPower(t, ctx, chain, incorrectUser, validators[0], 1_000_000)
res, _ = helpers.POASetPower(t, ctx, chain, incorrectUser, validators[0], 2_000_000, "--unsafe=true")
require.NoError(t, err)

res, err := chain.GetTransaction(res.TxHash)
require.NoError(t, err)
require.Contains(t, res.RawLog, poa.ErrNotAnAuthority.Error())
Expand Down
4 changes: 0 additions & 4 deletions simapp/test_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ from_scratch () {
# crisis
update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom": "stake","amount": "1000"}'

# x/POA
# allows gov & acc1 to perform actions on POA.
update_test_genesis '.app_state["poa"]["params"]["admins"]=["cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn","cosmos1hj5fveer5cjtn4wd6wstzugjfdxzl0xpxvjjvr"]'

# Allocate genesis accounts
# stake should ONLY be as much as they gentx with. No more.
BINARY genesis add-genesis-account $KEY 1000000000000stake,1000utest --keyring-backend $KEYRING
Expand Down

0 comments on commit e72e976

Please sign in to comment.