Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-account support #3433

Merged
merged 26 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a789675
feat: add multi-account support through a new txClient struct
cmwaters May 6, 2024
a7ce130
test: fixing tests wip
ninabarbakadze May 6, 2024
62bfb47
Merge remote-tracking branch 'origin' into cal/multi-accounts
ninabarbakadze May 6, 2024
454341b
chore: revert go mod replacement;
ninabarbakadze May 6, 2024
1949c0a
Merge branch 'main' into cal/multi-accounts
cmwaters May 7, 2024
059a257
lint and fix compile errors
cmwaters May 7, 2024
dd797e2
fix some of the tests
cmwaters May 7, 2024
a477eb3
fix a few more tests
cmwaters May 8, 2024
81fd741
test: fix direct tx gen
ninabarbakadze May 13, 2024
8d2668b
test: fix more tests
ninabarbakadze May 13, 2024
f72284a
test: fix prepare proposal context
ninabarbakadze May 15, 2024
f28c68b
fix some more tests
cmwaters May 21, 2024
0407bc2
Merge branch 'cal/multi-accounts' of github.com:celestiaorg/celestia-…
cmwaters May 21, 2024
c34a33a
fix a few more tests
cmwaters May 21, 2024
8599fcb
fix a few comments
cmwaters May 21, 2024
fd43334
Merge branch 'main' into cal/multi-accounts
cmwaters May 21, 2024
2c8509f
lint
cmwaters May 21, 2024
ed04b08
fix broken tests
cmwaters May 21, 2024
45257c7
fix square size test
cmwaters May 21, 2024
73f5b09
bump to 100 accounts
cmwaters May 21, 2024
8208599
Merge branch 'main' into cal/multi-accounts
cmwaters May 21, 2024
03d6006
add TestTxClientTestSuite to skipped tests
cmwaters May 21, 2024
2402099
Merge branch 'cal/multi-accounts' of github.com:celestiaorg/celestia-…
cmwaters May 21, 2024
44eb74c
lint
cmwaters May 21, 2024
6a36f1d
fix comments
cmwaters May 22, 2024
3af0856
Merge branch 'main' into cal/multi-accounts
cmwaters May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/errors/insufficient_gas_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) {
addr := testfactory.GetAddress(kr, account)
enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
acc := testutil.DirectQueryAccount(testApp, addr)
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), acc.GetSequence(), appconsts.LatestVersion)
signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence()))
require.NoError(t, err)

fee := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(feeAmount)))
b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0)
require.NoError(t, err)

msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), appconsts.LatestVersion, b)
msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b)
require.NoError(t, err)

sdkTx, err := signer.CreateTx([]sdk.Msg{msg}, user.SetGasLimit(gasLimit), user.SetFeeAmount(fee))
rawTx, err := signer.CreateTx([]sdk.Msg{msg}, user.SetGasLimit(gasLimit), user.SetFeeAmount(fee))
require.NoError(t, err)

decorator := ante.NewDeductFeeDecorator(testApp.AccountKeeper, testApp.BankKeeper, testApp.FeeGrantKeeper, nil)
anteHandler := sdk.ChainAnteDecorators(decorator)

sdkTx, err := signer.DecodeTx(rawTx)
require.NoError(t, err)

_, err = anteHandler(ctx, sdkTx, false)
require.True(t, apperr.IsInsufficientMinGasPrice(err))
actualGasPrice, err := apperr.ParseInsufficientMinGasPrice(err, gasPrice, gasLimit)
Expand Down
9 changes: 6 additions & 3 deletions app/errors/nonce_mismatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ func TestNonceMismatchIntegration(t *testing.T) {
enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
acc := testutil.DirectQueryAccount(testApp, addr)
// set the sequence to an incorrect value
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), 2, appconsts.LatestVersion)
signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence()+1))
require.NoError(t, err)

b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0)
require.NoError(t, err)

msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), appconsts.LatestVersion, b)
msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b)
require.NoError(t, err)

sdkTx, err := signer.CreateTx([]sdk.Msg{msg})
rawTx, err := signer.CreateTx([]sdk.Msg{msg})
require.NoError(t, err)

decorator := ante.NewSigVerificationDecorator(testApp.AccountKeeper, encCfg.TxConfig.SignModeHandler())
anteHandler := sdk.ChainAnteDecorators(decorator)

sdkTx, err := signer.DecodeTx(rawTx)
require.NoError(t, err)

// We set simulate to true here to bypass having to initialize the
// accounts public key.
_, err = anteHandler(ctx, sdkTx, true)
Expand Down
4 changes: 2 additions & 2 deletions app/test/big_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() {
},
}

signer, err := testnode.NewSignerFromContext(s.cctx, s.accounts[0])
txClient, err := testnode.NewTxClientFromContext(s.cctx)
require.NoError(t, err)

for _, tc := range testCases {
s.Run(tc.name, func() {
subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second)
defer cancel()
res, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimitAndFee(1e9, appconsts.DefaultMinGasPrice))
res, err := txClient.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimitAndFee(1e9, appconsts.DefaultMinGasPrice))
require.Error(t, err)
require.NotNil(t, res)
require.Equal(t, tc.want, res.Code, res.Logs)
Expand Down
30 changes: 15 additions & 15 deletions app/test/check_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/celestiaorg/celestia-app/v2/pkg/user"
testutil "github.com/celestiaorg/celestia-app/v2/test/util"
"github.com/celestiaorg/celestia-app/v2/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v2/test/util/testfactory"
blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
Expand Down Expand Up @@ -49,6 +48,7 @@ func TestCheckTx(t *testing.T) {
name: "normal transaction, CheckTxType_New",
checkType: abci.CheckTxType_New,
getTx: func() []byte {
// TODO might have to change back to 1
cmwaters marked this conversation as resolved.
Show resolved Hide resolved
signer := createSigner(t, kr, accs[0], encCfg.TxConfig, 1)
btx := blobfactory.RandBlobTxsWithNamespacesAndSigner(
signer,
Expand Down Expand Up @@ -112,8 +112,8 @@ func TestCheckTx(t *testing.T) {
checkType: abci.CheckTxType_New,
getTx: func() []byte {
signer := createSigner(t, kr, accs[4], encCfg.TxConfig, 5)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Address().String(), 10_000, 10)
tx, err := signer.CreatePayForBlob(blobs, opts...)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Account(accs[4]).Address().String(), 10_000, 10)
tx, _, err := signer.CreatePayForBlobs(accs[4], blobs, opts...)
require.NoError(t, err)
return tx
},
Expand All @@ -124,8 +124,8 @@ func TestCheckTx(t *testing.T) {
checkType: abci.CheckTxType_New,
getTx: func() []byte {
signer := createSigner(t, kr, accs[5], encCfg.TxConfig, 6)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Address().String(), 1_000, 1)
tx, err := signer.CreatePayForBlob(blobs, opts...)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Account(accs[5]).Address().String(), 1_000, 1)
tx, _, err := signer.CreatePayForBlobs(accs[5], blobs, opts...)
require.NoError(t, err)
return tx
},
Expand All @@ -136,8 +136,8 @@ func TestCheckTx(t *testing.T) {
checkType: abci.CheckTxType_New,
getTx: func() []byte {
signer := createSigner(t, kr, accs[6], encCfg.TxConfig, 7)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Address().String(), 10_000, 1)
tx, err := signer.CreatePayForBlob(blobs, opts...)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Account(accs[6]).Address().String(), 10_000, 1)
tx, _, err := signer.CreatePayForBlobs(accs[6], blobs, opts...)
require.NoError(t, err)
return tx
},
Expand All @@ -148,8 +148,8 @@ func TestCheckTx(t *testing.T) {
checkType: abci.CheckTxType_New,
getTx: func() []byte {
signer := createSigner(t, kr, accs[7], encCfg.TxConfig, 8)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Address().String(), 100_000, 1)
tx, err := signer.CreatePayForBlob(blobs, opts...)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Account(accs[7]).Address().String(), 100_000, 1)
tx, _, err := signer.CreatePayForBlobs(accs[7], blobs, opts...)
require.NoError(t, err)
return tx
},
Expand All @@ -160,8 +160,9 @@ func TestCheckTx(t *testing.T) {
checkType: abci.CheckTxType_New,
getTx: func() []byte {
signer := createSigner(t, kr, accs[8], encCfg.TxConfig, 9)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Address().String(), 1_000_000, 1)
tx, err := signer.CreatePayForBlob(blobs, opts...)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Account(accs[8]).Address().String(), 1_000_000, 1)
// TODO: go back to the sequences here and handle it
cmwaters marked this conversation as resolved.
Show resolved Hide resolved
tx, _, err := signer.CreatePayForBlobs(accs[8], blobs, opts...)
require.NoError(t, err)
return tx
},
Expand All @@ -172,8 +173,8 @@ func TestCheckTx(t *testing.T) {
checkType: abci.CheckTxType_New,
getTx: func() []byte {
signer := createSigner(t, kr, accs[9], encCfg.TxConfig, 10)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Address().String(), 10_000_000, 1)
tx, err := signer.CreatePayForBlob(blobs, opts...)
_, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), signer.Account(accs[9]).Address().String(), 10_000_000, 1)
tx, _, err := signer.CreatePayForBlobs(accs[9], blobs, opts...)
require.NoError(t, err)
return tx
},
Expand All @@ -190,8 +191,7 @@ func TestCheckTx(t *testing.T) {
}

func createSigner(t *testing.T, kr keyring.Keyring, accountName string, enc client.TxConfig, accNum uint64) *user.Signer {
addr := testfactory.GetAddress(kr, accountName)
signer, err := user.NewSigner(kr, nil, addr, enc, testutil.ChainID, accNum, 0, appconsts.LatestVersion)
signer, err := user.NewSigner(kr, enc, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(accountName, accNum, 0))
require.NoError(t, err)
return signer
}
2 changes: 1 addition & 1 deletion app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *IntegrationTestSuite) SetupSuite() {

for _, acc := range s.accounts {
addr := testfactory.GetAddress(s.cctx.Keyring, acc)
_, _, err := user.QueryAccount(s.cctx.GoContext(), s.cctx.GRPCClient, s.ecfg, addr.String())
_, _, err := user.QueryAccount(s.cctx.GoContext(), s.cctx.GRPCClient, s.cctx.InterfaceRegistry, addr)
require.NoError(t, err)
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/test/prepare_proposal_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func TestTimeInPrepareProposalContext(t *testing.T) {
// sign and submit the transactions
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msgs, account := tt.msgFunc()
addr := testfactory.GetAddress(cctx.Keyring, account)
signer, err := user.SetupSigner(cctx.GoContext(), cctx.Keyring, cctx.GRPCClient, addr, ecfg)
msgs, _ := tt.msgFunc()
// addr := testfactory.GetAddress(cctx.Keyring, account)
txClient, err := user.SetupTxClient(cctx.GoContext(), cctx.Keyring, cctx.GRPCClient, ecfg)
require.NoError(t, err)
res, err := signer.SubmitTx(cctx.GoContext(), msgs, user.SetGasLimit(1000000), user.SetFee(2000))
res, err := txClient.SubmitTx(cctx.GoContext(), msgs, user.SetGasLimit(1000000), user.SetFee(2000))
if tt.expectedCode != abci.CodeTypeOK {
require.Error(t, err)
} else {
Expand Down
145 changes: 71 additions & 74 deletions app/test/priority_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package app_test

import (
"encoding/hex"
// "encoding/hex"
"sort"
"sync"
// "sync"
"testing"
"time"

"github.com/celestiaorg/celestia-app/v2/app"
"github.com/celestiaorg/celestia-app/v2/app/encoding"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
// "github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/user"
"github.com/celestiaorg/celestia-app/v2/test/util/blobfactory"
// "github.com/celestiaorg/celestia-app/v2/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v2/test/util/testfactory"
"github.com/celestiaorg/celestia-app/v2/test/util/testnode"
blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
"github.com/celestiaorg/go-square/namespace"
// blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
// "github.com/celestiaorg/go-square/namespace"
sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/ethereum/go-ethereum/accounts"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
// abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
rpctypes "github.com/tendermint/tendermint/rpc/core/types"
)
Expand Down Expand Up @@ -58,81 +59,77 @@ func (s *PriorityTestSuite) SetupSuite() {

for _, acc := range cfg.Genesis.Accounts() {
addr := sdk.AccAddress(acc.PubKey.Address())
signer, err := user.SetupSigner(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, addr, s.ecfg)
signer.SetPollTime(time.Millisecond * 300)
client, err := user.SetupTxClient(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, s.ecfg, user.WithDefaultAddress(addr))
require.NoError(t, err)
s.signers = append(s.signers, signer)
s.signers = append(s.signers, client.Signer())
}
}

// TestPriorityByGasPrice tests that transactions are sorted by gas price when
// they are included in a block. It does this by submitting blobs with random
// gas prices, and then compares the ordering of the transactions after they are
// committed.
func (s *PriorityTestSuite) TestPriorityByGasPrice() {
t := s.T()

// quickly submit blobs with a random fee

hashes := make(chan string, len(s.signers))
blobSize := uint32(100)
gasLimit := blobtypes.DefaultEstimateGas([]uint32{blobSize})
wg := &sync.WaitGroup{}
for _, signer := range s.signers {
wg.Add(1)
signer := signer // new variable per iteration
go func() {
defer wg.Done()
// ensure that it is greater than the min gas price
gasPrice := float64(s.rand.Intn(1000)+1) * appconsts.DefaultMinGasPrice
resp, err := signer.SubmitPayForBlob(
s.cctx.GoContext(),
blobfactory.ManyBlobs(
s.rand,
[]namespace.Namespace{namespace.RandomBlobNamespace()},
[]int{100}),
user.SetGasLimitAndFee(gasLimit, gasPrice),
)
require.NoError(t, err)
require.Equal(t, abci.CodeTypeOK, resp.Code, resp.RawLog)
hashes <- resp.TxHash
}()
}

wg.Wait()
close(hashes)

err := s.cctx.WaitForNextBlock()
require.NoError(t, err)

// get the responses for each tx for analysis and sort by height
// note: use rpc types because they contain the tx index
heightMap := make(map[int64][]*rpctypes.ResultTx)
for hash := range hashes {
// use the core rpc type because it contains the tx index
hash, err := hex.DecodeString(hash)
require.NoError(t, err)
coreRes, err := s.cctx.Client.Tx(s.cctx.GoContext(), hash, false)
require.NoError(t, err)
heightMap[coreRes.Height] = append(heightMap[coreRes.Height], coreRes)
}
require.GreaterOrEqual(t, len(heightMap), 1)

// check that the transactions in each height are sorted by fee after
// sorting by index
highestNumOfTxsPerBlock := 0
for _, responses := range heightMap {
responses = sortByIndex(responses)
require.True(t, isSortedByFee(t, s.ecfg, responses))
if len(responses) > highestNumOfTxsPerBlock {
highestNumOfTxsPerBlock = len(responses)
}
}

// check that there was at least one block with more than three transactions
// in it. This is more of a sanity check than a test.
require.Greater(t, highestNumOfTxsPerBlock, 3)
}
// func (s *PriorityTestSuite) TestPriorityByGasPrice() {
// t := s.T()

// // quickly submit blobs with a random fee

// hashes := make(chan string, len(s.signers))
// blobSize := uint32(100)
// gasLimit := blobtypes.DefaultEstimateGas([]uint32{blobSize})
// wg := &sync.WaitGroup{}
// for _, signer := range s.signers {
// wg.Add(1)
// signer := signer // new variable per iteration
// go func() {
// defer wg.Done()
// // ensure that it is greater than the min gas price
// gasPrice := float64(s.rand.Intn(1000)+1) * appconsts.DefaultMinGasPrice
// blobs := blobfactory.ManyBlobs(s.rand, []namespace.Namespace{namespace.RandomBlobNamespace()}, []int{100})
// resp, _, err := signer.CreatePayForBlobs(
// s.cctx.GoContext(), signer.Account(string(user.Account.Address())).String(),blobs,
// user.SetGasLimitAndFee(gasLimit, gasPrice),
// )
// require.NoError(t, err)
// require.Equal(t, abci.CodeTypeOK, resp.Code, resp.RawLog)
// hashes <- resp.TxHash
// }()
// }

// wg.Wait()
// close(hashes)

// err := s.cctx.WaitForNextBlock()
// require.NoError(t, err)

// // get the responses for each tx for analysis and sort by height
// // note: use rpc types because they contain the tx index
// heightMap := make(map[int64][]*rpctypes.ResultTx)
// for hash := range hashes {
// // use the core rpc type because it contains the tx index
// hash, err := hex.DecodeString(hash)
// require.NoError(t, err)
// coreRes, err := s.cctx.Client.Tx(s.cctx.GoContext(), hash, false)
// require.NoError(t, err)
// heightMap[coreRes.Height] = append(heightMap[coreRes.Height], coreRes)
// }
// require.GreaterOrEqual(t, len(heightMap), 1)

// // check that the transactions in each height are sorted by fee after
// // sorting by index
// highestNumOfTxsPerBlock := 0
// for _, responses := range heightMap {
// responses = sortByIndex(responses)
// require.True(t, isSortedByFee(t, s.ecfg, responses))
// if len(responses) > highestNumOfTxsPerBlock {
// highestNumOfTxsPerBlock = len(responses)
// }
// }

// // check that there was at least one block with more than three transactions
// // in it. This is more of a sanity check than a test.
// require.Greater(t, highestNumOfTxsPerBlock, 3)
// }

func sortByIndex(txs []*rpctypes.ResultTx) []*rpctypes.ResultTx {
sort.Slice(txs, func(i, j int) bool {
Expand Down
4 changes: 2 additions & 2 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestProcessProposal(t *testing.T) {
accounts := testfactory.GenerateAccounts(6)
testApp, kr := testutil.SetupTestAppWithGenesisValSet(app.DefaultConsensusParams(), accounts...)
infos := queryAccountInfo(testApp, accounts, kr)
addr := testfactory.GetAddress(kr, accounts[0])
signer, err := user.NewSigner(kr, nil, addr, enc, testutil.ChainID, infos[0].AccountNum, infos[0].Sequence, appconsts.LatestVersion)
// addr := testfactory.GetAddress(kr, accounts[0])
signer, err := user.NewSigner(kr, enc, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(accounts[0], infos[0].AccountNum, infos[0].Sequence))
require.NoError(t, err)

// create 4 single blob blobTxs that are signed with valid account numbers
Expand Down
Loading
Loading