Aggregating all testing functionality into one directory (#38)

This commit is contained in:
David Terpay 2023-03-29 14:30:53 -04:00 committed by GitHub
parent bd5104ffc7
commit c368f4cb00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 188 additions and 835 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/skip-mev/pob/abci"
"github.com/skip-mev/pob/mempool"
testutils "github.com/skip-mev/pob/testutils"
"github.com/skip-mev/pob/x/auction/ante"
"github.com/skip-mev/pob/x/auction/keeper"
auctiontypes "github.com/skip-mev/pob/x/auction/types"
@ -27,7 +28,7 @@ type ABCITestSuite struct {
// mempool setup
mempool *mempool.AuctionMempool
logger log.Logger
encodingConfig encodingConfig
encodingConfig testutils.EncodingConfig
proposalHandler *abci.ProposalHandler
// auction bid setup
@ -36,16 +37,16 @@ type ABCITestSuite struct {
// auction setup
auctionKeeper keeper.Keeper
bankKeeper *MockBankKeeper
accountKeeper *MockAccountKeeper
distrKeeper *MockDistributionKeeper
stakingKeeper *MockStakingKeeper
bankKeeper *testutils.MockBankKeeper
accountKeeper *testutils.MockAccountKeeper
distrKeeper *testutils.MockDistributionKeeper
stakingKeeper *testutils.MockStakingKeeper
auctionDecorator ante.AuctionDecorator
key *storetypes.KVStoreKey
authorityAccount sdk.AccAddress
// account set up
accounts []Account
accounts []testutils.Account
balances sdk.Coins
random *rand.Rand
nonces map[string]uint64
@ -57,10 +58,10 @@ func TestABCISuite(t *testing.T) {
func (suite *ABCITestSuite) SetupTest() {
// General config
suite.encodingConfig = createTestEncodingConfig()
suite.encodingConfig = testutils.CreateTestEncodingConfig()
suite.random = rand.New(rand.NewSource(time.Now().Unix()))
suite.key = sdk.NewKVStoreKey(auctiontypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, sdk.NewTransientStoreKey("transient_test"))
suite.key = storetypes.NewKVStoreKey(auctiontypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx
// Mempool set up
@ -70,11 +71,11 @@ func (suite *ABCITestSuite) SetupTest() {
// Mock keepers set up
ctrl := gomock.NewController(suite.T())
suite.accountKeeper = NewMockAccountKeeper(ctrl)
suite.accountKeeper = testutils.NewMockAccountKeeper(ctrl)
suite.accountKeeper.EXPECT().GetModuleAddress(auctiontypes.ModuleName).Return(sdk.AccAddress{}).AnyTimes()
suite.bankKeeper = NewMockBankKeeper(ctrl)
suite.distrKeeper = NewMockDistributionKeeper(ctrl)
suite.stakingKeeper = NewMockStakingKeeper(ctrl)
suite.bankKeeper = testutils.NewMockBankKeeper(ctrl)
suite.distrKeeper = testutils.NewMockDistributionKeeper(ctrl)
suite.stakingKeeper = testutils.NewMockStakingKeeper(ctrl)
suite.authorityAccount = sdk.AccAddress([]byte("authority"))
// Auction keeper / decorator set up
@ -92,7 +93,7 @@ func (suite *ABCITestSuite) SetupTest() {
suite.auctionDecorator = ante.NewAuctionDecorator(suite.auctionKeeper, suite.encodingConfig.TxConfig.TxDecoder(), suite.encodingConfig.TxConfig.TxEncoder(), suite.mempool)
// Accounts set up
suite.accounts = RandomAccounts(suite.random, 1)
suite.accounts = testutils.RandomAccounts(suite.random, 1)
suite.balances = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000000000000000000)))
suite.nonces = make(map[string]uint64)
for _, acc := range suite.accounts {
@ -151,10 +152,10 @@ func (suite *ABCITestSuite) createFilledMempool(numNormalTxs, numAuctionTxs, num
acc := suite.accounts[randomIndex]
// create a few random msgs
randomMsgs := createRandomMsgs(acc.Address, 3)
randomMsgs := testutils.CreateRandomMsgs(acc.Address, 3)
nonce := suite.nonces[acc.Address.String()]
randomTx, err := createTx(suite.encodingConfig.TxConfig, acc, nonce, randomMsgs)
randomTx, err := testutils.CreateTx(suite.encodingConfig.TxConfig, acc, nonce, randomMsgs)
suite.Require().NoError(err)
suite.nonces[acc.Address.String()]++
@ -173,13 +174,13 @@ func (suite *ABCITestSuite) createFilledMempool(numNormalTxs, numAuctionTxs, num
// create a new auction bid msg with numBundledTxs bundled transactions
nonce := suite.nonces[acc.Address.String()]
bidMsg, err := createMsgAuctionBid(suite.encodingConfig.TxConfig, acc, suite.auctionBidAmount, nonce, numBundledTxs)
bidMsg, err := testutils.CreateMsgAuctionBid(suite.encodingConfig.TxConfig, acc, suite.auctionBidAmount, nonce, numBundledTxs)
suite.nonces[acc.Address.String()] += uint64(numBundledTxs)
suite.Require().NoError(err)
// create the auction tx
nonce = suite.nonces[acc.Address.String()]
auctionTx, err := createTx(suite.encodingConfig.TxConfig, acc, nonce, []sdk.Msg{bidMsg})
auctionTx, err := testutils.CreateTx(suite.encodingConfig.TxConfig, acc, nonce, []sdk.Msg{bidMsg})
suite.Require().NoError(err)
// insert the auction tx into the global mempool
@ -684,11 +685,11 @@ func (suite *ABCITestSuite) TestProcessProposal() {
{
"auction tx with frontrunning",
func() {
randomAccount := RandomAccounts(suite.random, 1)[0]
randomAccount := testutils.RandomAccounts(suite.random, 1)[0]
bidder := suite.accounts[0]
bid := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(696969696969)))
nonce := suite.nonces[bidder.Address.String()]
frontRunningTx, _ = createAuctionTxWithSigners(suite.encodingConfig.TxConfig, suite.accounts[0], bid, nonce+1, []Account{bidder, randomAccount})
frontRunningTx, _ = testutils.CreateAuctionTxWithSigners(suite.encodingConfig.TxConfig, suite.accounts[0], bid, nonce+1, []testutils.Account{bidder, randomAccount})
suite.Require().NotNil(frontRunningTx)
numNormalTxs = 100
@ -703,11 +704,11 @@ func (suite *ABCITestSuite) TestProcessProposal() {
{
"auction tx with frontrunning, but frontrunning protection disabled",
func() {
randomAccount := RandomAccounts(suite.random, 1)[0]
randomAccount := testutils.RandomAccounts(suite.random, 1)[0]
bidder := suite.accounts[0]
bid := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(696969696969)))
nonce := suite.nonces[bidder.Address.String()]
frontRunningTx, _ = createAuctionTxWithSigners(suite.encodingConfig.TxConfig, suite.accounts[0], bid, nonce+1, []Account{bidder, randomAccount})
frontRunningTx, _ = testutils.CreateAuctionTxWithSigners(suite.encodingConfig.TxConfig, suite.accounts[0], bid, nonce+1, []testutils.Account{bidder, randomAccount})
suite.Require().NotNil(frontRunningTx)
numAuctionTxs = 0

View File

View File

@ -9,6 +9,7 @@ import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/skip-mev/pob/mempool"
testutils "github.com/skip-mev/pob/testutils"
auctiontypes "github.com/skip-mev/pob/x/auction/types"
"github.com/stretchr/testify/suite"
)
@ -16,11 +17,11 @@ import (
type IntegrationTestSuite struct {
suite.Suite
encCfg encodingConfig
encCfg testutils.EncodingConfig
mempool *mempool.AuctionMempool
ctx sdk.Context
random *rand.Rand
accounts []Account
accounts []testutils.Account
nonces map[string]uint64
}
@ -30,13 +31,13 @@ func TestMempoolTestSuite(t *testing.T) {
func (suite *IntegrationTestSuite) SetupTest() {
// Mempool setup
suite.encCfg = createTestEncodingConfig()
suite.encCfg = testutils.CreateTestEncodingConfig()
suite.mempool = mempool.NewAuctionMempool(suite.encCfg.TxConfig.TxDecoder(), 0)
suite.ctx = sdk.NewContext(nil, cmtproto.Header{}, false, log.NewNopLogger())
// Init accounts
suite.random = rand.New(rand.NewSource(time.Now().Unix()))
suite.accounts = RandomAccounts(suite.random, 5)
suite.accounts = testutils.RandomAccounts(suite.random, 5)
suite.nonces = make(map[string]uint64)
for _, acc := range suite.accounts {
@ -51,13 +52,13 @@ func (suite *IntegrationTestSuite) CreateFilledMempool(numNormalTxs, numAuctionT
// Insert a bunch of normal transactions into the global mempool
for i := 0; i < numNormalTxs; i++ {
// create a few random msgs
randomMsgs := createRandomMsgs(3)
// randomly select an account to create the tx
randomIndex := suite.random.Intn(len(suite.accounts))
acc := suite.accounts[randomIndex]
nonce := suite.nonces[acc.Address.String()]
randomTx, err := createTx(suite.encCfg.TxConfig, acc, nonce, randomMsgs)
randomMsgs := testutils.CreateRandomMsgs(acc.Address, 3)
randomTx, err := testutils.CreateTx(suite.encCfg.TxConfig, acc, nonce, randomMsgs)
suite.Require().NoError(err)
suite.nonces[acc.Address.String()]++
@ -71,19 +72,19 @@ func (suite *IntegrationTestSuite) CreateFilledMempool(numNormalTxs, numAuctionT
// Insert a bunch of auction transactions into the global mempool and auction mempool
for i := 0; i < numAuctionTxs; i++ {
// randomly select a bidder to create the tx
acc := RandomAccounts(suite.random, 1)[0]
acc := testutils.RandomAccounts(suite.random, 1)[0]
// create a new auction bid msg with numBundledTxs bundled transactions
priority := suite.random.Int63n(100) + 1
bid := sdk.NewCoins(sdk.NewInt64Coin("foo", priority))
nonce := suite.nonces[acc.Address.String()]
bidMsg, err := createMsgAuctionBid(suite.encCfg.TxConfig, acc, bid, nonce, numBundledTxs)
bidMsg, err := testutils.CreateMsgAuctionBid(suite.encCfg.TxConfig, acc, bid, nonce, numBundledTxs)
suite.nonces[acc.Address.String()] += uint64(numBundledTxs)
suite.Require().NoError(err)
// create the auction tx
nonce = suite.nonces[acc.Address.String()]
auctionTx, err := createTx(suite.encCfg.TxConfig, acc, nonce, []sdk.Msg{bidMsg})
auctionTx, err := testutils.CreateTx(suite.encCfg.TxConfig, acc, nonce, []sdk.Msg{bidMsg})
suite.Require().NoError(err)
// insert the auction tx into the global mempool

View File

@ -1,148 +0,0 @@
package mempool_test
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
auctiontypes "github.com/skip-mev/pob/x/auction/types"
)
type encodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
func createTestEncodingConfig() encodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
banktypes.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)
codec := codec.NewProtoCodec(interfaceRegistry)
return encodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Amino: cdc,
}
}
type Account struct {
PrivKey cryptotypes.PrivKey
PubKey cryptotypes.PubKey
Address sdk.AccAddress
ConsKey cryptotypes.PrivKey
}
func (acc Account) Equals(acc2 Account) bool {
return acc.Address.Equals(acc2.Address)
}
func RandomAccounts(r *rand.Rand, n int) []Account {
accs := make([]Account, n)
for i := 0; i < n; i++ {
pkSeed := make([]byte, 15)
r.Read(pkSeed)
accs[i].PrivKey = secp256k1.GenPrivKeyFromSecret(pkSeed)
accs[i].PubKey = accs[i].PrivKey.PubKey()
accs[i].Address = sdk.AccAddress(accs[i].PubKey.Address())
accs[i].ConsKey = ed25519.GenPrivKeyFromSecret(pkSeed)
}
return accs
}
func createTx(txCfg client.TxConfig, account Account, nonce uint64, msgs []sdk.Msg) (authsigning.Tx, error) {
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(msgs...); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: account.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}
func createRandomMsgs(numberMsgs int) []sdk.Msg {
msgs := make([]sdk.Msg, numberMsgs)
for i := 0; i < numberMsgs; i++ {
msgs[i] = &banktypes.MsgSend{
FromAddress: sdk.AccAddress([]byte("addr1_______________")).String(),
ToAddress: sdk.AccAddress([]byte("addr2_______________")).String(),
}
}
return msgs
}
// createMsgAuctionBid creates a new MsgAuctionBid with numberMsgs of referenced transactions embedded into the message and the inputted bid/bidder.
func createMsgAuctionBid(txCfg client.TxConfig, bidder Account, bid sdk.Coins, nonce uint64, numberMsgs int) (*auctiontypes.MsgAuctionBid, error) {
bidMsg := &auctiontypes.MsgAuctionBid{
Bidder: bidder.Address.String(),
Bid: bid,
Transactions: make([][]byte, numberMsgs),
}
for i := 0; i < numberMsgs; i++ {
txBuilder := txCfg.NewTxBuilder()
msgs := []sdk.Msg{
&banktypes.MsgSend{
FromAddress: bidder.Address.String(),
ToAddress: bidder.Address.String(),
},
}
if err := txBuilder.SetMsgs(msgs...); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: bidder.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce + uint64(i),
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
bz, err := txCfg.TxEncoder()(txBuilder.GetTx())
if err != nil {
return nil, err
}
bidMsg.Transactions[i] = bz
}
return bidMsg, nil
}

View File

@ -1,4 +1,4 @@
package abci_test
package test
import (
"reflect"

View File

@ -1,4 +1,4 @@
package abci_test
package test
import (
"math/rand"
@ -18,14 +18,14 @@ import (
auctiontypes "github.com/skip-mev/pob/x/auction/types"
)
type encodingConfig struct {
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
func createTestEncodingConfig() encodingConfig {
func CreateTestEncodingConfig() EncodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
@ -35,7 +35,7 @@ func createTestEncodingConfig() encodingConfig {
codec := codec.NewProtoCodec(interfaceRegistry)
return encodingConfig{
return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
@ -71,7 +71,7 @@ func RandomAccounts(r *rand.Rand, n int) []Account {
return accs
}
func createTx(txCfg client.TxConfig, account Account, nonce uint64, msgs []sdk.Msg) (authsigning.Tx, error) {
func CreateTx(txCfg client.TxConfig, account Account, nonce uint64, msgs []sdk.Msg) (authsigning.Tx, error) {
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(msgs...); err != nil {
return nil, err
@ -92,7 +92,78 @@ func createTx(txCfg client.TxConfig, account Account, nonce uint64, msgs []sdk.M
return txBuilder.GetTx(), nil
}
func createRandomMsgs(acc sdk.AccAddress, numberMsgs int) []sdk.Msg {
func CreateRandomTx(txCfg client.TxConfig, account Account, nonce, numberMsgs uint64) (authsigning.Tx, error) {
msgs := make([]sdk.Msg, numberMsgs)
for i := 0; i < int(numberMsgs); i++ {
msgs[i] = &banktypes.MsgSend{
FromAddress: account.Address.String(),
ToAddress: account.Address.String(),
}
}
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(msgs...); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: account.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}
func CreateAuctionTxWithSigners(txCfg client.TxConfig, bidder Account, bid sdk.Coins, nonce uint64, signers []Account) (authsigning.Tx, error) {
bidMsg := &auctiontypes.MsgAuctionBid{
Bidder: bidder.Address.String(),
Bid: bid,
Transactions: make([][]byte, len(signers)),
}
for i := 0; i < len(signers); i++ {
randomMsg := CreateRandomMsgs(signers[i].Address, 1)
randomTx, err := CreateTx(txCfg, signers[i], 0, randomMsg)
if err != nil {
return nil, err
}
bz, err := txCfg.TxEncoder()(randomTx)
if err != nil {
return nil, err
}
bidMsg.Transactions[i] = bz
}
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(bidMsg); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: bidder.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}
func CreateRandomMsgs(acc sdk.AccAddress, numberMsgs int) []sdk.Msg {
msgs := make([]sdk.Msg, numberMsgs)
for i := 0; i < numberMsgs; i++ {
msgs[i] = &banktypes.MsgSend{
@ -104,7 +175,7 @@ func createRandomMsgs(acc sdk.AccAddress, numberMsgs int) []sdk.Msg {
return msgs
}
func createMsgAuctionBid(txCfg client.TxConfig, bidder Account, bid sdk.Coins, nonce uint64, numberMsgs int) (*auctiontypes.MsgAuctionBid, error) {
func CreateMsgAuctionBid(txCfg client.TxConfig, bidder Account, bid sdk.Coins, nonce uint64, numberMsgs int) (*auctiontypes.MsgAuctionBid, error) {
bidMsg := &auctiontypes.MsgAuctionBid{
Bidder: bidder.Address.String(),
Bid: bid,
@ -146,45 +217,3 @@ func createMsgAuctionBid(txCfg client.TxConfig, bidder Account, bid sdk.Coins, n
return bidMsg, nil
}
func createAuctionTxWithSigners(txCfg client.TxConfig, bidder Account, bid sdk.Coins, nonce uint64, signers []Account) (authsigning.Tx, error) {
bidMsg := &auctiontypes.MsgAuctionBid{
Bidder: bidder.Address.String(),
Bid: bid,
Transactions: make([][]byte, len(signers)),
}
for i := 0; i < len(signers); i++ {
randomMsg := createRandomMsgs(signers[i].Address, 1)
randomTx, err := createTx(txCfg, signers[i], 0, randomMsg)
if err != nil {
return nil, err
}
bz, err := txCfg.TxEncoder()(randomTx)
if err != nil {
return nil, err
}
bidMsg.Transactions[i] = bz
}
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(bidMsg); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: bidder.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}

View File

@ -10,6 +10,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/golang/mock/gomock"
"github.com/skip-mev/pob/mempool"
testutils "github.com/skip-mev/pob/testutils"
"github.com/skip-mev/pob/x/auction/ante"
"github.com/skip-mev/pob/x/auction/keeper"
auctiontypes "github.com/skip-mev/pob/x/auction/types"
@ -21,15 +22,15 @@ type AnteTestSuite struct {
ctx sdk.Context
// mempool setup
encodingConfig encodingConfig
encodingConfig testutils.EncodingConfig
random *rand.Rand
// auction setup
auctionKeeper keeper.Keeper
bankKeeper *MockBankKeeper
accountKeeper *MockAccountKeeper
distrKeeper *MockDistributionKeeper
stakingKeeper *MockStakingKeeper
bankKeeper *testutils.MockBankKeeper
accountKeeper *testutils.MockAccountKeeper
distrKeeper *testutils.MockDistributionKeeper
stakingKeeper *testutils.MockStakingKeeper
auctionDecorator ante.AuctionDecorator
key *storetypes.KVStoreKey
authorityAccount sdk.AccAddress
@ -41,19 +42,19 @@ func TestAnteTestSuite(t *testing.T) {
func (suite *AnteTestSuite) SetupTest() {
// General config
suite.encodingConfig = createTestEncodingConfig()
suite.encodingConfig = testutils.CreateTestEncodingConfig()
suite.random = rand.New(rand.NewSource(time.Now().Unix()))
suite.key = sdk.NewKVStoreKey(auctiontypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, sdk.NewTransientStoreKey("transient_test"))
suite.key = storetypes.NewKVStoreKey(auctiontypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx
// Keepers set up
ctrl := gomock.NewController(suite.T())
suite.accountKeeper = NewMockAccountKeeper(ctrl)
suite.accountKeeper = testutils.NewMockAccountKeeper(ctrl)
suite.accountKeeper.EXPECT().GetModuleAddress(auctiontypes.ModuleName).Return(sdk.AccAddress{}).AnyTimes()
suite.bankKeeper = NewMockBankKeeper(ctrl)
suite.distrKeeper = NewMockDistributionKeeper(ctrl)
suite.stakingKeeper = NewMockStakingKeeper(ctrl)
suite.bankKeeper = testutils.NewMockBankKeeper(ctrl)
suite.distrKeeper = testutils.NewMockDistributionKeeper(ctrl)
suite.stakingKeeper = testutils.NewMockStakingKeeper(ctrl)
suite.authorityAccount = sdk.AccAddress([]byte("authority"))
suite.auctionKeeper = keeper.NewKeeper(
suite.encodingConfig.Codec,
@ -82,13 +83,13 @@ func (suite *AnteTestSuite) executeAnteHandler(tx sdk.Tx, balance sdk.Coins) (sd
func (suite *AnteTestSuite) TestAnteHandler() {
var (
// Bid set up
bidder = RandomAccounts(suite.random, 1)[0]
bidder = testutils.RandomAccounts(suite.random, 1)[0]
bid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000)))
balance = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10000)))
signers = []Account{bidder}
signers = []testutils.Account{bidder}
// Top bidding auction tx set up
topBidder = RandomAccounts(suite.random, 1)[0]
topBidder = testutils.RandomAccounts(suite.random, 1)[0]
topBid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100)))
insertTopBid = true
@ -168,30 +169,30 @@ func (suite *AnteTestSuite) TestAnteHandler() {
insertTopBid = true
topBidder = bidder
topBid = bid
signers = []Account{}
signers = []testutils.Account{}
},
true,
},
{
"invalid frontrunning auction bid tx",
func() {
randomAccount := RandomAccounts(suite.random, 2)
randomAccount := testutils.RandomAccounts(suite.random, 2)
bidder := randomAccount[0]
otherUser := randomAccount[1]
insertTopBid = false
signers = []Account{bidder, otherUser}
signers = []testutils.Account{bidder, otherUser}
},
false,
},
{
"valid frontrunning auction bid tx",
func() {
randomAccount := RandomAccounts(suite.random, 2)
randomAccount := testutils.RandomAccounts(suite.random, 2)
bidder := randomAccount[0]
otherUser := randomAccount[1]
signers = []Account{bidder, otherUser}
signers = []testutils.Account{bidder, otherUser}
frontRunningProtection = false
},
true,
@ -199,11 +200,11 @@ func (suite *AnteTestSuite) TestAnteHandler() {
{
"invalid sandwiching auction bid tx",
func() {
randomAccount := RandomAccounts(suite.random, 2)
randomAccount := testutils.RandomAccounts(suite.random, 2)
bidder := randomAccount[0]
otherUser := randomAccount[1]
signers = []Account{bidder, otherUser, bidder}
signers = []testutils.Account{bidder, otherUser, bidder}
frontRunningProtection = true
},
false,
@ -211,7 +212,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
{
"invalid auction bid tx with many signers",
func() {
signers = RandomAccounts(suite.random, 10)
signers = testutils.RandomAccounts(suite.random, 10)
frontRunningProtection = true
},
false,
@ -236,7 +237,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
// Insert the top bid into the mempool
mempool := mempool.NewAuctionMempool(suite.encodingConfig.TxConfig.TxDecoder(), 0)
if insertTopBid {
topAuctionTx, err := createAuctionTxWithSigners(suite.encodingConfig.TxConfig, topBidder, topBid, 0, []Account{})
topAuctionTx, err := testutils.CreateAuctionTxWithSigners(suite.encodingConfig.TxConfig, topBidder, topBid, 0, []testutils.Account{})
suite.Require().NoError(err)
suite.Require().Equal(0, mempool.CountTx())
suite.Require().Equal(0, mempool.CountAuctionTx())
@ -246,7 +247,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
}
// Create the actual auction tx and insert into the mempool
auctionTx, err := createAuctionTxWithSigners(suite.encodingConfig.TxConfig, bidder, bid, 0, signers)
auctionTx, err := testutils.CreateAuctionTxWithSigners(suite.encodingConfig.TxConfig, bidder, bid, 0, signers)
suite.Require().NoError(err)
// Execute the ante handler

View File

@ -1,144 +0,0 @@
package ante_test
import (
"reflect"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/golang/mock/gomock"
)
type MockAccountKeeper struct {
ctrl *gomock.Controller
recorder *MockAccountKeeperMockRecorder
}
type MockAccountKeeperMockRecorder struct {
mock *MockAccountKeeper
}
func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper {
mock := &MockAccountKeeper{ctrl: ctrl}
mock.recorder = &MockAccountKeeperMockRecorder{mock}
return mock
}
func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
return m.recorder
}
func (m *MockAccountKeeper) GetModuleAddress(name string) sdk.AccAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetModuleAddress", name)
ret0, _ := ret[0].(sdk.AccAddress)
return ret0
}
func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name)
}
type MockBankKeeper struct {
ctrl *gomock.Controller
recorder *MockBankKeeperMockRecorder
}
type MockBankKeeperMockRecorder struct {
mock *MockBankKeeper
}
func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper {
mock := &MockBankKeeper{ctrl: ctrl}
mock.recorder = &MockBankKeeperMockRecorder{mock}
return mock
}
func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
return m.recorder
}
func (m *MockBankKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0 := ret[0].(sdk.Coins)
return ret0
}
func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr)
}
func (m *MockBankKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt)
return nil
}
func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt)
}
type MockDistributionKeeperRecorder struct {
mock *MockDistributionKeeper
}
type MockDistributionKeeper struct {
ctrl *gomock.Controller
recorder *MockDistributionKeeperRecorder
}
func NewMockDistributionKeeper(ctrl *gomock.Controller) *MockDistributionKeeper {
mock := &MockDistributionKeeper{ctrl: ctrl}
mock.recorder = &MockDistributionKeeperRecorder{mock}
return mock
}
func (m *MockDistributionKeeper) EXPECT() *MockDistributionKeeperRecorder {
return m.recorder
}
func (m *MockDistributionKeeper) GetPreviousProposerConsAddr(ctx sdk.Context) sdk.ConsAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPreviousProposerConsAddr", ctx)
ret0 := ret[0].(sdk.ConsAddress)
return ret0
}
func (mr *MockDistributionKeeperRecorder) GetPreviousProposerConsAddr(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPreviousProposerConsAddr", reflect.TypeOf((*MockDistributionKeeper)(nil).GetPreviousProposerConsAddr), ctx)
}
type MockStakingKeeperRecorder struct {
mock *MockStakingKeeper
}
type MockStakingKeeper struct {
ctrl *gomock.Controller
recorder *MockStakingKeeperRecorder
}
func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper {
mock := &MockStakingKeeper{ctrl: ctrl}
mock.recorder = &MockStakingKeeperRecorder{mock}
return mock
}
func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperRecorder {
return m.recorder
}
func (m *MockStakingKeeper) ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) stakingtypes.ValidatorI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidatorByConsAddr", ctx, consAddr)
ret0 := ret[0].(stakingtypes.ValidatorI)
return ret0
}
func (mr *MockStakingKeeperRecorder) ValidatorByConsAddr(ctx, consAddr any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorByConsAddr", reflect.TypeOf((*MockStakingKeeper)(nil).ValidatorByConsAddr), ctx, consAddr)
}

View File

@ -1,147 +0,0 @@
package ante_test
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
auctiontypes "github.com/skip-mev/pob/x/auction/types"
)
type encodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
func createTestEncodingConfig() encodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
banktypes.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)
auctiontypes.RegisterInterfaces(interfaceRegistry)
codec := codec.NewProtoCodec(interfaceRegistry)
return encodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Amino: cdc,
}
}
type Account struct {
PrivKey cryptotypes.PrivKey
PubKey cryptotypes.PubKey
Address sdk.AccAddress
ConsKey cryptotypes.PrivKey
}
func (acc Account) Equals(acc2 Account) bool {
return acc.Address.Equals(acc2.Address)
}
func RandomAccounts(r *rand.Rand, n int) []Account {
accs := make([]Account, n)
for i := 0; i < n; i++ {
pkSeed := make([]byte, 15)
r.Read(pkSeed)
accs[i].PrivKey = secp256k1.GenPrivKeyFromSecret(pkSeed)
accs[i].PubKey = accs[i].PrivKey.PubKey()
accs[i].Address = sdk.AccAddress(accs[i].PubKey.Address())
accs[i].ConsKey = ed25519.GenPrivKeyFromSecret(pkSeed)
}
return accs
}
func createTx(txCfg client.TxConfig, account Account, nonce uint64, msgs []sdk.Msg) (authsigning.Tx, error) {
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(msgs...); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: account.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}
func createRandomMsgs(acc sdk.AccAddress, numberMsgs int) []sdk.Msg {
msgs := make([]sdk.Msg, numberMsgs)
for i := 0; i < numberMsgs; i++ {
msgs[i] = &banktypes.MsgSend{
FromAddress: acc.String(),
ToAddress: acc.String(),
}
}
return msgs
}
func createAuctionTxWithSigners(txCfg client.TxConfig, bidder Account, bid sdk.Coins, nonce uint64, signers []Account) (authsigning.Tx, error) {
bidMsg := &auctiontypes.MsgAuctionBid{
Bidder: bidder.Address.String(),
Bid: bid,
Transactions: make([][]byte, len(signers)),
}
for i := 0; i < len(signers); i++ {
randomMsg := createRandomMsgs(signers[i].Address, 1)
randomTx, err := createTx(txCfg, signers[i], 0, randomMsg)
if err != nil {
return nil, err
}
bz, err := txCfg.TxEncoder()(randomTx)
if err != nil {
return nil, err
}
bidMsg.Transactions[i] = bz
}
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(bidMsg); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: bidder.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}

View File

@ -5,6 +5,7 @@ import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
testutils "github.com/skip-mev/pob/testutils"
"github.com/skip-mev/pob/x/auction/keeper"
auctiontypes "github.com/skip-mev/pob/x/auction/types"
)
@ -12,7 +13,7 @@ import (
func (suite *KeeperTestSuite) TestValidateAuctionMsg() {
var (
// Tx building variables
accounts = []Account{} // tracks the order of signers in the bundle
accounts = []testutils.Account{} // tracks the order of signers in the bundle
balance = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10000)))
bid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000)))
@ -29,7 +30,7 @@ func (suite *KeeperTestSuite) TestValidateAuctionMsg() {
)
rnd := rand.New(rand.NewSource(time.Now().Unix()))
bidder := RandomAccounts(rnd, 1)[0]
bidder := testutils.RandomAccounts(rnd, 1)[0]
cases := []struct {
name string
@ -65,60 +66,60 @@ func (suite *KeeperTestSuite) TestValidateAuctionMsg() {
// reset the balance and bid to their original values
bid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000)))
balance = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10000)))
accounts = RandomAccounts(rnd, int(maxBundleSize+1))
accounts = testutils.RandomAccounts(rnd, int(maxBundleSize+1))
},
false,
},
{
"frontrunning bundle",
func() {
randomAccount := RandomAccounts(rnd, 1)[0]
accounts = []Account{bidder, randomAccount}
randomAccount := testutils.RandomAccounts(rnd, 1)[0]
accounts = []testutils.Account{bidder, randomAccount}
},
false,
},
{
"sandwiching bundle",
func() {
randomAccount := RandomAccounts(rnd, 1)[0]
accounts = []Account{bidder, randomAccount, bidder}
randomAccount := testutils.RandomAccounts(rnd, 1)[0]
accounts = []testutils.Account{bidder, randomAccount, bidder}
},
false,
},
{
"valid bundle",
func() {
randomAccount := RandomAccounts(rnd, 1)[0]
accounts = []Account{randomAccount, randomAccount, bidder, bidder, bidder}
randomAccount := testutils.RandomAccounts(rnd, 1)[0]
accounts = []testutils.Account{randomAccount, randomAccount, bidder, bidder, bidder}
},
true,
},
{
"valid bundle with only bidder txs",
func() {
accounts = []Account{bidder, bidder, bidder, bidder}
accounts = []testutils.Account{bidder, bidder, bidder, bidder}
},
true,
},
{
"valid bundle with only random txs from single same user",
func() {
randomAccount := RandomAccounts(rnd, 1)[0]
accounts = []Account{randomAccount, randomAccount, randomAccount, randomAccount}
randomAccount := testutils.RandomAccounts(rnd, 1)[0]
accounts = []testutils.Account{randomAccount, randomAccount, randomAccount, randomAccount}
},
true,
},
{
"invalid bundle with random accounts",
func() {
accounts = RandomAccounts(rnd, 2)
accounts = testutils.RandomAccounts(rnd, 2)
},
false,
},
{
"disabled front-running protection",
func() {
accounts = RandomAccounts(rnd, 10)
accounts = testutils.RandomAccounts(rnd, 10)
frontRunningProtection = false
},
true,
@ -126,7 +127,7 @@ func (suite *KeeperTestSuite) TestValidateAuctionMsg() {
{
"invalid bundle that does not outbid the highest bid",
func() {
accounts = []Account{bidder, bidder, bidder}
accounts = []testutils.Account{bidder, bidder, bidder}
highestBid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(500)))
bid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(500)))
},
@ -174,7 +175,7 @@ func (suite *KeeperTestSuite) TestValidateAuctionMsg() {
// Create the bundle of transactions ordered by accounts
bundle := make([]sdk.Tx, 0)
for _, acc := range accounts {
tx, err := createRandomTx(suite.encCfg.TxConfig, acc, 0, 1)
tx, err := testutils.CreateRandomTx(suite.encCfg.TxConfig, acc, 0, 1)
suite.Require().NoError(err)
bundle = append(bundle, tx)
}
@ -192,10 +193,10 @@ func (suite *KeeperTestSuite) TestValidateAuctionMsg() {
func (suite *KeeperTestSuite) TestValidateBundle() {
// TODO: Update this to be multi-dimensional to test multi-sig
// https://github.com/skip-mev/pob/issues/14
var accounts []Account // tracks the order of signers in the bundle
var accounts []testutils.Account // tracks the order of signers in the bundle
rng := rand.New(rand.NewSource(time.Now().Unix()))
bidder := RandomAccounts(rng, 1)[0]
bidder := testutils.RandomAccounts(rng, 1)[0]
cases := []struct {
name string
@ -205,69 +206,69 @@ func (suite *KeeperTestSuite) TestValidateBundle() {
{
"valid empty bundle",
func() {
accounts = make([]Account, 0)
accounts = make([]testutils.Account, 0)
},
true,
},
{
"valid single tx bundle",
func() {
accounts = []Account{bidder}
accounts = []testutils.Account{bidder}
},
true,
},
{
"valid multi-tx bundle by same account",
func() {
accounts = []Account{bidder, bidder, bidder, bidder}
accounts = []testutils.Account{bidder, bidder, bidder, bidder}
},
true,
},
{
"valid single-tx bundle by a different account",
func() {
randomAccount := RandomAccounts(rng, 1)[0]
accounts = []Account{randomAccount}
randomAccount := testutils.RandomAccounts(rng, 1)[0]
accounts = []testutils.Account{randomAccount}
},
true,
},
{
"valid multi-tx bundle by a different accounts",
func() {
randomAccount := RandomAccounts(rng, 1)[0]
accounts = []Account{randomAccount, bidder}
randomAccount := testutils.RandomAccounts(rng, 1)[0]
accounts = []testutils.Account{randomAccount, bidder}
},
true,
},
{
"invalid frontrunning bundle",
func() {
randomAccount := RandomAccounts(rng, 1)[0]
accounts = []Account{bidder, randomAccount}
randomAccount := testutils.RandomAccounts(rng, 1)[0]
accounts = []testutils.Account{bidder, randomAccount}
},
false,
},
{
"invalid sandwiching bundle",
func() {
randomAccount := RandomAccounts(rng, 1)[0]
accounts = []Account{bidder, randomAccount, bidder}
randomAccount := testutils.RandomAccounts(rng, 1)[0]
accounts = []testutils.Account{bidder, randomAccount, bidder}
},
false,
},
{
"invalid multi account bundle",
func() {
accounts = RandomAccounts(rng, 3)
accounts = testutils.RandomAccounts(rng, 3)
},
false,
},
{
"invalid multi account bundle without bidder",
func() {
randomAccount1 := RandomAccounts(rng, 1)[0]
randomAccount2 := RandomAccounts(rng, 1)[0]
accounts = []Account{randomAccount1, randomAccount2}
randomAccount1 := testutils.RandomAccounts(rng, 1)[0]
randomAccount2 := testutils.RandomAccounts(rng, 1)[0]
accounts = []testutils.Account{randomAccount1, randomAccount2}
},
false,
},
@ -284,7 +285,7 @@ func (suite *KeeperTestSuite) TestValidateBundle() {
bundle := make([]sdk.Tx, 0)
for _, acc := range accounts {
// Create a random tx
tx, err := createRandomTx(suite.encCfg.TxConfig, acc, 0, 1)
tx, err := testutils.CreateRandomTx(suite.encCfg.TxConfig, acc, 0, 1)
suite.Require().NoError(err)
bundle = append(bundle, tx)
}

View File

@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/golang/mock/gomock"
"github.com/skip-mev/pob/mempool"
testutils "github.com/skip-mev/pob/testutils"
"github.com/skip-mev/pob/x/auction/keeper"
"github.com/skip-mev/pob/x/auction/types"
@ -18,11 +19,11 @@ type KeeperTestSuite struct {
suite.Suite
auctionKeeper keeper.Keeper
bankKeeper *MockBankKeeper
accountKeeper *MockAccountKeeper
distrKeeper *MockDistributionKeeper
stakingKeeper *MockStakingKeeper
encCfg encodingConfig
bankKeeper *testutils.MockBankKeeper
accountKeeper *testutils.MockAccountKeeper
distrKeeper *testutils.MockDistributionKeeper
stakingKeeper *testutils.MockStakingKeeper
encCfg testutils.EncodingConfig
ctx sdk.Context
msgServer types.MsgServer
key *storetypes.KVStoreKey
@ -36,19 +37,19 @@ func TestKeeperTestSuite(t *testing.T) {
}
func (suite *KeeperTestSuite) SetupTest() {
suite.encCfg = createTestEncodingConfig()
suite.key = sdk.NewKVStoreKey(types.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, sdk.NewTransientStoreKey("transient_test"))
suite.encCfg = testutils.CreateTestEncodingConfig()
suite.key = storetypes.NewKVStoreKey(types.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx
ctrl := gomock.NewController(suite.T())
suite.accountKeeper = NewMockAccountKeeper(ctrl)
suite.accountKeeper = testutils.NewMockAccountKeeper(ctrl)
suite.accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(sdk.AccAddress{}).AnyTimes()
suite.bankKeeper = NewMockBankKeeper(ctrl)
suite.distrKeeper = NewMockDistributionKeeper(ctrl)
suite.stakingKeeper = NewMockStakingKeeper(ctrl)
suite.bankKeeper = testutils.NewMockBankKeeper(ctrl)
suite.distrKeeper = testutils.NewMockDistributionKeeper(ctrl)
suite.stakingKeeper = testutils.NewMockStakingKeeper(ctrl)
suite.authorityAccount = sdk.AccAddress([]byte("authority"))
suite.auctionKeeper = keeper.NewKeeper(
suite.encCfg.Codec,

View File

@ -1,144 +0,0 @@
package keeper_test
import (
"reflect"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/golang/mock/gomock"
)
type MockAccountKeeper struct {
ctrl *gomock.Controller
recorder *MockAccountKeeperMockRecorder
}
type MockAccountKeeperMockRecorder struct {
mock *MockAccountKeeper
}
func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper {
mock := &MockAccountKeeper{ctrl: ctrl}
mock.recorder = &MockAccountKeeperMockRecorder{mock}
return mock
}
func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
return m.recorder
}
func (m *MockAccountKeeper) GetModuleAddress(name string) sdk.AccAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetModuleAddress", name)
ret0, _ := ret[0].(sdk.AccAddress)
return ret0
}
func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name)
}
type MockBankKeeper struct {
ctrl *gomock.Controller
recorder *MockBankKeeperMockRecorder
}
type MockBankKeeperMockRecorder struct {
mock *MockBankKeeper
}
func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper {
mock := &MockBankKeeper{ctrl: ctrl}
mock.recorder = &MockBankKeeperMockRecorder{mock}
return mock
}
func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
return m.recorder
}
func (m *MockBankKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0 := ret[0].(sdk.Coins)
return ret0
}
func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr)
}
func (m *MockBankKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt)
return nil
}
func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt)
}
type MockDistributionKeeperRecorder struct {
mock *MockDistributionKeeper
}
type MockDistributionKeeper struct {
ctrl *gomock.Controller
recorder *MockDistributionKeeperRecorder
}
func NewMockDistributionKeeper(ctrl *gomock.Controller) *MockDistributionKeeper {
mock := &MockDistributionKeeper{ctrl: ctrl}
mock.recorder = &MockDistributionKeeperRecorder{mock}
return mock
}
func (m *MockDistributionKeeper) EXPECT() *MockDistributionKeeperRecorder {
return m.recorder
}
func (m *MockDistributionKeeper) GetPreviousProposerConsAddr(ctx sdk.Context) sdk.ConsAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPreviousProposerConsAddr", ctx)
ret0 := ret[0].(sdk.ConsAddress)
return ret0
}
func (mr *MockDistributionKeeperRecorder) GetPreviousProposerConsAddr(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPreviousProposerConsAddr", reflect.TypeOf((*MockDistributionKeeper)(nil).GetPreviousProposerConsAddr), ctx)
}
type MockStakingKeeperRecorder struct {
mock *MockStakingKeeper
}
type MockStakingKeeper struct {
ctrl *gomock.Controller
recorder *MockStakingKeeperRecorder
}
func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper {
mock := &MockStakingKeeper{ctrl: ctrl}
mock.recorder = &MockStakingKeeperRecorder{mock}
return mock
}
func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperRecorder {
return m.recorder
}
func (m *MockStakingKeeper) ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) stakingtypes.ValidatorI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidatorByConsAddr", ctx, consAddr)
ret0 := ret[0].(stakingtypes.ValidatorI)
return ret0
}
func (mr *MockStakingKeeperRecorder) ValidatorByConsAddr(ctx, consAddr any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorByConsAddr", reflect.TypeOf((*MockStakingKeeper)(nil).ValidatorByConsAddr), ctx, consAddr)
}

View File

@ -6,12 +6,13 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
testutils "github.com/skip-mev/pob/testutils"
"github.com/skip-mev/pob/x/auction/types"
)
func (suite *KeeperTestSuite) TestMsgAuctionBid() {
rng := rand.New(rand.NewSource(time.Now().Unix()))
accounts := RandomAccounts(rng, 4)
accounts := testutils.RandomAccounts(rng, 4)
bidder := accounts[0]
escrow := accounts[1]

View File

@ -1,99 +0,0 @@
package keeper_test
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
type encodingConfig struct {
InterfaceRegistry codectypes.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
func createTestEncodingConfig() encodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
banktypes.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)
codec := codec.NewProtoCodec(interfaceRegistry)
return encodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Amino: cdc,
}
}
type Account struct {
PrivKey cryptotypes.PrivKey
PubKey cryptotypes.PubKey
Address sdk.AccAddress
ConsKey cryptotypes.PrivKey
}
func (acc Account) Equals(acc2 Account) bool {
return acc.Address.Equals(acc2.Address)
}
func RandomAccounts(r *rand.Rand, n int) []Account {
accs := make([]Account, n)
for i := 0; i < n; i++ {
pkSeed := make([]byte, 15)
r.Read(pkSeed)
accs[i].PrivKey = secp256k1.GenPrivKeyFromSecret(pkSeed)
accs[i].PubKey = accs[i].PrivKey.PubKey()
accs[i].Address = sdk.AccAddress(accs[i].PubKey.Address())
accs[i].ConsKey = ed25519.GenPrivKeyFromSecret(pkSeed)
}
return accs
}
func createRandomTx(txCfg client.TxConfig, account Account, nonce, numberMsgs uint64) (authsigning.Tx, error) {
msgs := make([]sdk.Msg, numberMsgs)
for i := 0; i < int(numberMsgs); i++ {
msgs[i] = &banktypes.MsgSend{
FromAddress: account.Address.String(),
ToAddress: account.Address.String(),
}
}
txBuilder := txCfg.NewTxBuilder()
if err := txBuilder.SetMsgs(msgs...); err != nil {
return nil, err
}
sigV2 := signing.SignatureV2{
PubKey: account.PrivKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: txCfg.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: nonce,
}
if err := txBuilder.SetSignatures(sigV2); err != nil {
return nil, err
}
return txBuilder.GetTx(), nil
}