mirror of https://github.com/poanetwork/gecko.git
Improved UX for xput tests
This commit is contained in:
parent
9da52187b1
commit
ddf784284b
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,10 +26,14 @@ import (
|
|||
type Wallet struct {
|
||||
networkID uint32
|
||||
chainID ids.ID
|
||||
|
||||
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
|
||||
|
||||
|
@ -37,7 +42,7 @@ type Wallet struct {
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ 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"
|
||||
)
|
||||
|
||||
|
@ -17,6 +18,9 @@ import (
|
|||
type Wallet struct {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue