From ddf784284b10d544845a912307ab2c11b83ec8e7 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 18 Mar 2020 16:10:03 -0400 Subject: [PATCH] Improved UX for xput tests --- xputtest/avm.go | 3 ++- xputtest/avmwallet/wallet.go | 33 ++++++++++++++++++++++++------- xputtest/avmwallet/wallet_test.go | 21 ++++++++++---------- xputtest/chainwallet/wallet.go | 26 +++++++++++++++++++++--- xputtest/spchain.go | 3 ++- 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/xputtest/avm.go b/xputtest/avm.go index b096531..01dbd6d 100644 --- a/xputtest/avm.go +++ b/xputtest/avm.go @@ -22,7 +22,7 @@ import ( // benchmark an instance of the avm func (n *network) benchmarkAVM(chain *platformvm.CreateChainTx) { genesisBytes := chain.GenesisData - wallet, err := avmwallet.NewWallet(n.networkID, chain.ID(), config.AvaTxFee) + wallet, err := avmwallet.NewWallet(n.log, n.networkID, chain.ID(), config.AvaTxFee) n.log.AssertNoError(err) cb58 := formatting.CB58{} @@ -106,6 +106,7 @@ func (n *network) IssueAVM(chainID ids.ID, assetID ids.ID, wallet *avmwallet.Wal // If we are done issuing txs, return from the function if numAccepted+numPending >= config.NumTxs { n.log.Info("done with test") + net.ec.Stop() return } } diff --git a/xputtest/avmwallet/wallet.go b/xputtest/avmwallet/wallet.go index 226765b..bffe752 100644 --- a/xputtest/avmwallet/wallet.go +++ b/xputtest/avmwallet/wallet.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/hashing" + "github.com/ava-labs/gecko/utils/logging" "github.com/ava-labs/gecko/utils/math" "github.com/ava-labs/gecko/utils/timer" "github.com/ava-labs/gecko/utils/wrappers" @@ -25,19 +26,23 @@ import ( type Wallet struct { networkID uint32 chainID ids.ID - clock timer.Clock - codec codec.Codec - keychain *secp256k1fx.Keychain // Mapping from public address to the SigningKeys - utxoSet *UTXOSet // Mapping from utxoIDs to UTXOs - balance map[[32]byte]uint64 - txFee uint64 + + clock timer.Clock + codec codec.Codec + log logging.Logger + + keychain *secp256k1fx.Keychain // Mapping from public address to the SigningKeys + utxoSet *UTXOSet // Mapping from utxoIDs to UTXOs + + balance map[[32]byte]uint64 + txFee uint64 txsSent int32 txs []*avm.Tx } // NewWallet returns a new Wallet -func NewWallet(networkID uint32, chainID ids.ID, txFee uint64) (*Wallet, error) { +func NewWallet(log logging.Logger, networkID uint32, chainID ids.ID, txFee uint64) (*Wallet, error) { c := codec.NewDefault() errs := wrappers.Errs{} errs.Add( @@ -54,6 +59,7 @@ func NewWallet(networkID uint32, chainID ids.ID, txFee uint64) (*Wallet, error) networkID: networkID, chainID: chainID, codec: c, + log: log, keychain: secp256k1fx.NewKeychain(), utxoSet: &UTXOSet{}, balance: make(map[[32]byte]uint64), @@ -249,10 +255,17 @@ func (w *Wallet) CreateTx(assetID ids.ID, amount uint64, destAddr ids.ShortID) ( // Generate them all on test initialization so tx generation is not bottleneck // in testing func (w *Wallet) GenerateTxs(numTxs int, assetID ids.ID) error { + w.log.Info("Generating %d transactions", numTxs) + ctx := snow.DefaultContextTest() ctx.NetworkID = w.networkID ctx.ChainID = w.chainID + frequency := numTxs / 50 + if frequency > 1000 { + frequency = 1000 + } + w.txs = make([]*avm.Tx, numTxs) for i := 0; i < numTxs; i++ { addr, err := w.CreateAddress() @@ -271,8 +284,14 @@ func (w *Wallet) GenerateTxs(numTxs int, assetID ids.ID) error { w.AddUTXO(utxo) } + if numGenerated := i + 1; numGenerated%frequency == 0 { + w.log.Info("Generated %d out of %d transactions", numGenerated, numTxs) + } + w.txs[i] = tx } + + w.log.Info("Finished generating %d transactions", numTxs) return nil } diff --git a/xputtest/avmwallet/wallet_test.go b/xputtest/avmwallet/wallet_test.go index 52ac797..377368d 100644 --- a/xputtest/avmwallet/wallet_test.go +++ b/xputtest/avmwallet/wallet_test.go @@ -11,6 +11,7 @@ import ( "github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/formatting" + "github.com/ava-labs/gecko/utils/logging" "github.com/ava-labs/gecko/utils/units" "github.com/ava-labs/gecko/vms/avm" "github.com/ava-labs/gecko/vms/secp256k1fx" @@ -18,7 +19,7 @@ import ( func TestNewWallet(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -29,7 +30,7 @@ func TestNewWallet(t *testing.T) { func TestWalletGetAddress(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -45,7 +46,7 @@ func TestWalletGetAddress(t *testing.T) { func TestWalletGetMultipleAddresses(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -65,7 +66,7 @@ func TestWalletGetMultipleAddresses(t *testing.T) { func TestWalletEmptyBalance(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -77,7 +78,7 @@ func TestWalletEmptyBalance(t *testing.T) { func TestWalletAddUTXO(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -99,7 +100,7 @@ func TestWalletAddUTXO(t *testing.T) { func TestWalletAddInvalidUTXO(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -118,7 +119,7 @@ func TestWalletAddInvalidUTXO(t *testing.T) { func TestWalletCreateTx(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -168,7 +169,7 @@ func TestWalletCreateTx(t *testing.T) { func TestWalletImportKey(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -193,7 +194,7 @@ func TestWalletImportKey(t *testing.T) { func TestWalletString(t *testing.T) { chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(12345, chainID, 0) + w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0) if err != nil { t.Fatal(err) } @@ -225,7 +226,7 @@ func TestWalletWithGenesis(t *testing.T) { ctx.NetworkID = 12345 ctx.ChainID = ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - w, err := NewWallet(ctx.NetworkID, ctx.ChainID, 0) + w, err := NewWallet(logging.NoLog{}, ctx.NetworkID, ctx.ChainID, 0) if err != nil { t.Fatal(err) } diff --git a/xputtest/chainwallet/wallet.go b/xputtest/chainwallet/wallet.go index a96ff2e..c96e115 100644 --- a/xputtest/chainwallet/wallet.go +++ b/xputtest/chainwallet/wallet.go @@ -10,13 +10,17 @@ import ( "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/utils/crypto" + "github.com/ava-labs/gecko/utils/logging" "github.com/ava-labs/gecko/vms/spchainvm" ) // Wallet is a holder for keys and UTXOs. type Wallet struct { - networkID uint32 - chainID ids.ID + networkID uint32 + chainID ids.ID + + log logging.Logger + keychain *spchainvm.Keychain // Mapping from public address to the SigningKeys accountSet map[[20]byte]spchainvm.Account // Mapping from addresses to accounts balance uint64 @@ -25,10 +29,11 @@ type Wallet struct { } // NewWallet ... -func NewWallet(networkID uint32, chainID ids.ID) *Wallet { +func NewWallet(log logging.Logger, networkID uint32, chainID ids.ID) *Wallet { return &Wallet{ networkID: networkID, chainID: chainID, + log: log, keychain: spchainvm.NewKeychain(networkID, chainID), accountSet: make(map[[20]byte]spchainvm.Account), } @@ -62,18 +67,33 @@ func (w *Wallet) Balance() uint64 { return w.balance } // Generate them all on test initialization so tx generation is not bottleneck // in testing func (w *Wallet) GenerateTxs(numTxs int) error { + w.log.Info("Generating %d transactions", numTxs) + ctx := snow.DefaultContextTest() ctx.NetworkID = w.networkID ctx.ChainID = w.chainID + frequency := numTxs / 50 + if frequency > 1000 { + frequency = 1000 + } + w.txs = make([]*spchainvm.Tx, numTxs) for i := range w.txs { tx, err := w.MakeTx() if err != nil { return err } + + if numGenerated := i + 1; numGenerated%frequency == 0 { + w.log.Info("Generated %d out of %d transactions", numGenerated, numTxs) + } + w.txs[i] = tx } + + w.log.Info("Finished generating %d transactions", numTxs) + return nil } diff --git a/xputtest/spchain.go b/xputtest/spchain.go index 70f6947..ddea05b 100644 --- a/xputtest/spchain.go +++ b/xputtest/spchain.go @@ -22,7 +22,7 @@ import ( // benchmark an instance of the sp chain func (n *network) benchmarkSPChain(chain *platformvm.CreateChainTx) { genesisBytes := chain.GenesisData - wallet := chainwallet.NewWallet(n.networkID, chain.ID()) + wallet := chainwallet.NewWallet(n.log, n.networkID, chain.ID()) codec := spchainvm.Codec{} accounts, err := codec.UnmarshalGenesis(genesisBytes) @@ -88,6 +88,7 @@ func (n *network) IssueSPChain(chainID ids.ID, wallet *chainwallet.Wallet) { } if numAccepted+numPending >= config.NumTxs { n.log.Info("done with test") + net.ec.Stop() return } }