Skip to content

Commit

Permalink
Lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwik committed Dec 8, 2023
1 parent 2b54498 commit f44455e
Show file tree
Hide file tree
Showing 37 changed files with 172 additions and 155 deletions.
3 changes: 2 additions & 1 deletion protocol/app/ante/basic_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante_test

import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"testing"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestValidateBasic_AppInjectedMsgWrapper(t *testing.T) {
privs, accNums, accSeqs = []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
}

tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID())
tx, err := suite.CreateTestTx(suite.Ctx, privs, accNums, accSeqs, suite.Ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT)
require.NoError(t, err)

if tc.isRecheck {
Expand Down
3 changes: 2 additions & 1 deletion protocol/app/ante/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante_test
import (
"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
assets "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
Expand Down Expand Up @@ -120,7 +121,7 @@ func TestValidateMsgType_FreeInfiniteGasDecorator(t *testing.T) {
// Empty private key, so tx's signature should be empty.
privs, accNums, accSeqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{}

tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID())
tx, err := suite.CreateTestTx(suite.Ctx, privs, accNums, accSeqs, suite.Ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT)
require.NoError(t, err)

resultCtx, err := antehandler(suite.Ctx, tx, false)
Expand Down
3 changes: 2 additions & 1 deletion protocol/app/ante/msg_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante_test
import (
errorsmod "cosmossdk.io/errors"
"fmt"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"golang.org/x/exp/slices"
"testing"

Expand Down Expand Up @@ -484,7 +485,7 @@ func runTest(t *testing.T, name string, msgs []sdk.Msg, mode txMode, expectedErr
require.NoError(t, suite.TxBuilder.SetMsgs(msgs...))
// Empty private key, so tx's signature should be empty.
privs, accNums, accSeqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID())
tx, err := suite.CreateTestTx(suite.Ctx, privs, accNums, accSeqs, suite.Ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT)
require.NoError(t, err)
suite.Ctx = getCtxWithTxMode(mode, suite)

Expand Down
1 change: 0 additions & 1 deletion protocol/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func TestAppIsFullyInitialized(t *testing.T) {
t.Run(name, func(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).WithAppOptions(tc.customFlags).Build()
tApp.InitChain()
tApp.App.EndBlocker()
uninitializedFields := getUninitializedStructFields(reflect.ValueOf(*tApp.App))

// Note that the daemon clients are currently hard coded as disabled in GetDefaultTestAppOptions.
Expand Down
4 changes: 3 additions & 1 deletion protocol/app/msgs/app_injected_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func TestAppInjectedMsgSamples_GetSigners(t *testing.T) {
_ = testTxBuilder.SetMsgs(sample.Msg)
sigTx, ok := testTxBuilder.GetTx().(authsigning.SigVerifiableTx)
require.True(t, ok)
require.Empty(t, sigTx.GetSigners())
signers, err := sigTx.GetSigners()
require.NoError(t, err)
require.Empty(t, signers)
}
}

Expand Down
6 changes: 4 additions & 2 deletions protocol/app/prepare/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ func TestPrepareProposalHandler(t *testing.T) {
MaxTxBytes: tc.maxBytes,
}

response := handler(ctx, req)
// TODO(CORE-538): Check status of error returned from handler
response, _ := handler(ctx, &req)
require.Equal(t, tc.expectedTxs, response.Txs)
})
}
Expand Down Expand Up @@ -443,7 +444,8 @@ func TestPrepareProposalHandler_OtherTxs(t *testing.T) {
MaxTxBytes: 100_000, // something large.
}

response := handler(ctx, req)
// TODO(CORE-538): Check status of error returned from handler
response, _ := handler(ctx, &req)
require.Equal(t, tc.expectedTxs, response.Txs)
})
}
Expand Down
3 changes: 2 additions & 1 deletion protocol/app/process/full_node_process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func TestFullNodeProcessProposalHandler(t *testing.T) {
req := abci.RequestProcessProposal{Txs: tc.txsBytes}

// Run.
resp := handler(ctx, req)
// TODO(CORE-538): Update tests to check err returned by handler.
resp, _ := handler(ctx, &req)

// Validate.
require.Equal(t, acceptResponse, resp)
Expand Down
3 changes: 2 additions & 1 deletion protocol/app/process/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ func TestProcessProposalHandler_Error(t *testing.T) {
req := abci.RequestProcessProposal{Txs: tc.txsBytes}

// Run.
resp := handler(ctx, req)
// TODO(CORE-538): Update tests to check err returned by handler
resp, _ := handler(ctx, &req)

// Validate.
require.Equal(t, tc.expectedResponse, resp)
Expand Down
4 changes: 2 additions & 2 deletions protocol/app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app_test
import (
"encoding/json"
"fmt"
dbm "github.com/cosmos/cosmos-db"
"io"
"math/rand"
"os"
Expand All @@ -14,7 +15,6 @@ import (
"cosmossdk.io/store"
evidencetypes "cosmossdk.io/x/evidence/types"
feegranttypes "cosmossdk.io/x/feegrant"
dbm "github.com/cometbft/cometbft-db"
tmjson "github.com/cometbft/cometbft/libs/json"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestAppStateDeterminism(t *testing.T) {
for j := 0; j < numTimesToRunPerSeed; j++ {
var logger log.Logger
if simcli.FlagVerboseValue {
logger = log.TestingLogger()
logger = log.NewTestLogger(t)
} else {
logger = log.NewNopLogger()
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/lib/ante/nested_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestValidateNestedMsg_IterateEachMsgSample(t *testing.T) {

for _, tc := range allTestCases {
t.Run(tc.name, func(t *testing.T) {
nestedMsg, err := gov.NewMsgSubmitProposal(tc.msgs, nil, "", "", "", "")
nestedMsg, err := gov.NewMsgSubmitProposal(tc.msgs, nil, "", "", "", "", false)
require.NoError(t, err)
result := ante.ValidateNestedMsg(nestedMsg)
require.Equal(t, tc.expectedErr, result)
Expand Down
16 changes: 6 additions & 10 deletions protocol/scripts/iaviewer/iaviewer.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Originally forked from https://github.com/cosmos/iavl/blob/v0.20.0/cmd/iaviewer/main.go
// TODO(CORE-538): Update this fork for Cosmos 0.50 upgrade.
package main

import (
"bytes"
"cosmossdk.io/log"
"crypto/sha256"
"encoding/hex"
"fmt"
dbm "github.com/cosmos/cosmos-db"
"os"
"path/filepath"
"regexp"
"strings"

dbm "github.com/cometbft/cometbft-db"
"github.com/cosmos/iavl"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -202,7 +204,7 @@ func OpenDB(dir string) (dbm.DB, error) {
return nil, fmt.Errorf("cannot cut paths on %s", dir)
}
name := dir[cut+1:]
db, err := dbm.NewGoLevelDB(name, dir[:cut])
db, err := dbm.NewGoLevelDB(name, dir[:cut], nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -265,10 +267,7 @@ func ReadTree(db dbm.DB, version uint64, prefix []byte) (*iavl.MutableTree, erro
db = dbm.NewPrefixDB(db, prefix)
}

tree, err := iavl.NewMutableTree(db, DefaultCacheSize, false)
if err != nil {
return nil, err
}
tree := iavl.NewMutableTree(db, DefaultCacheSize, false, log.NewLogger(os.Stdout))
ver, err := tree.LoadVersion(int64(version))
fmt.Printf("Tree %s version: %d\n", prefix, ver)
return tree, err
Expand All @@ -291,10 +290,7 @@ func PrintTree(tree *iavl.MutableTree, prefix string) error {
}
return false
})
hash, err := tree.Hash()
if err != nil {
return err
}
hash := tree.Hash()
fmt.Printf("Tree %s Hash: %X\n", prefix, hash)
fmt.Printf("Tree %s Size: %X\n", prefix, tree.Size())
return nil
Expand Down
2 changes: 1 addition & 1 deletion protocol/testutil/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ func (tApp *TestApp) AdvanceToBlock(
parallelRecheckTxResponse, parallelRecheckTxErr := tApp.parallelApp.CheckTx(&recheckTxRequest)
require.Truef(
tApp.builder.t,
recheckTxResponse.Code == parallelRecheckTxResponse.Code && ((parallelRecheckTxErr == nil && parallelRecheckTxErr == nil) || (parallelRecheckTxErr != nil && parallelRecheckTxErr != nil)),
recheckTxResponse.Code == parallelRecheckTxResponse.Code && ((recheckTxResponse == nil && parallelRecheckTxErr == nil) || (recheckTxResponse != nil && parallelRecheckTxErr != nil)),
"Non-determinism detected during RecheckTx, expected %+v with err %+v, got %+v with err %+v.",
recheckTxResponse,
recheckTxErr,
Expand Down
33 changes: 16 additions & 17 deletions protocol/testutil/app/block_advancement.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"testing"
"time"

abcitypes "github.com/cometbft/cometbft/abci/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app"
testtx "github.com/dydxprotocol/v4-chain/protocol/testutil/tx"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
"github.com/stretchr/testify/require"
)

// BlockAdvancement holds orders and matches to be placed in a block. Using this struct and building
Expand Down Expand Up @@ -42,21 +40,22 @@ func (b BlockAdvancementWithErrors) AdvanceToBlock(
t *testing.T,
) sdktypes.Context {
advanceToBlockOptions := AdvanceToBlockOptions{
ValidateDeliverTxs: func(
ctx sdktypes.Context,
request abcitypes.RequestDeliverTx,
response abcitypes.ResponseDeliverTx,
txIndex int,
) (haltchain bool) {
expectedError, found := b.ExpectedDeliverTxErrors[txIndex]
if found && expectedError != "" {
require.True(t, response.IsErr(), "Expected CheckTx to error. Response: %+v", response)
require.Contains(t, response.Log, expectedError)
} else {
require.True(t, response.IsOK(), "Expected CheckTx to succeed. Response: %+v", response)
}
return false
},
// TODO(CORE-538): Validate the delivered txs.
//ValidateDeliverTxs: func(
// ctx sdktypes.Context,
// request abcitypes.RequestDeliverTx,
// response abcitypes.ResponseDeliverTx,
// txIndex int,
//) (haltchain bool) {
// expectedError, found := b.ExpectedDeliverTxErrors[txIndex]
// if found && expectedError != "" {
// require.True(t, response.IsErr(), "Expected CheckTx to error. Response: %+v", response)
// require.Contains(t, response.Log, expectedError)
// } else {
// require.True(t, response.IsOK(), "Expected CheckTx to succeed. Response: %+v", response)
// }
// return false
//},
}

deliverTxsOverride := b.BlockAdvancement.getDeliverTxs(ctx, tApp.App)
Expand Down
40 changes: 23 additions & 17 deletions protocol/testutil/app/gov.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package app

import (
"bytes"
"testing"
"time"

abcitypes "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
Expand Down Expand Up @@ -47,6 +45,7 @@ func SubmitAndTallyProposal(
TestMetadata,
TestTitle,
TestSummary,
false,
)
require.NoError(t, err)

Expand All @@ -72,27 +71,31 @@ func SubmitAndTallyProposal(

if expectSubmitProposalFails {
ctx = tApp.AdvanceToBlock(TestSubmitProposalTxHeight, AdvanceToBlockOptions{
ValidateDeliverTxs: func(
context sdk.Context,
request abcitypes.RequestDeliverTx,
response abcitypes.ResponseDeliverTx,
_ int,
) (haltChain bool) {
if bytes.Equal(request.Tx, submitProposalCheckTx.Tx) {
require.True(t, response.IsErr())
} else {
require.True(t, response.IsOK())
}
return false
},
// TODO(CORE-538): uncomment
//ValidateDeliverTxs: func(
// context sdk.Context,
// request abcitypes.RequestDeliverTx,
// response abcitypes.ResponseDeliverTx,
// _ int,
//) (haltChain bool) {
// if bytes.Equal(request.Tx, submitProposalCheckTx.Tx) {
// require.True(t, response.IsErr())
// } else {
// require.True(t, response.IsOK())
// }
// return false
//},
})
// Proposal submission failed. Return early.
return ctx
} else {
ctx = tApp.AdvanceToBlock(TestSubmitProposalTxHeight, AdvanceToBlockOptions{})
}

proposals := tApp.App.GovKeeper.GetProposals(ctx)
proposalsIterator, err := tApp.App.GovKeeper.Proposals.Iterate(ctx, nil)
require.NoError(t, err)
proposals, err := proposalsIterator.Values()
require.NoError(t, err)
require.Len(t, proposals, 1)

// Have all 4 validators vote for the proposal.
Expand Down Expand Up @@ -131,7 +134,10 @@ func SubmitAndTallyProposal(
BlockTime: ctx.BlockTime().Add(TestVotingPeriod).Add(1 * time.Second),
})

proposals = tApp.App.GovKeeper.GetProposals(ctx)
proposalsIterator, err = tApp.App.GovKeeper.Proposals.Iterate(ctx, nil)
require.NoError(t, err)
proposals, err = proposalsIterator.Values()
require.NoError(t, err)
require.Len(t, proposals, 1)
// Check that proposal was executed or failed as expected.
require.Equal(t, expectedProposalStatus, proposals[0].Status)
Expand Down
6 changes: 3 additions & 3 deletions protocol/testutil/keeper/assets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
dbm "github.com/cosmos/cosmos-db"
"testing"

"github.com/dydxprotocol/v4-chain/protocol/indexer/common"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/mocks"

storetypes "cosmossdk.io/store/types"
tmdb "github.com/cometbft/cometbft-db"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -49,7 +49,7 @@ func AssetsKeepers(
) {
var mockTimeProvider *mocks.TimeProvider
ctx = initKeepers(t, func(
db *tmdb.MemDB,
db *dbm.MemDB,
registry codectypes.InterfaceRegistry,
cdc *codec.ProtoCodec,
stateStore storetypes.CommitMultiStore,
Expand All @@ -70,7 +70,7 @@ func AssetsKeepers(

func createAssetsKeeper(
stateStore storetypes.CommitMultiStore,
db *tmdb.MemDB,
db *dbm.MemDB,
cdc *codec.ProtoCodec,
pk *priceskeeper.Keeper,
transientStoreKey storetypes.StoreKey,
Expand Down
Loading

0 comments on commit f44455e

Please sign in to comment.