Skip to content

Commit

Permalink
updated wallet to handle dynamic fees
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Jul 15, 2024
1 parent 270ab49 commit 6b8d844
Show file tree
Hide file tree
Showing 28 changed files with 2,381 additions and 736 deletions.
24 changes: 18 additions & 6 deletions vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ func TestBuildBlockBasic(t *testing.T) {
defer env.ctx.Lock.Unlock()

// Create a valid transaction
builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1])
builder, signer, feeCalc, err := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1])
require.NoError(err)
utx, err := builder.NewCreateChainTx(
testSubnet1.ID(),
nil,
constants.AVMID,
nil,
"chain name",
feeCalc,
)
require.NoError(err)
tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx)
Expand Down Expand Up @@ -111,7 +113,8 @@ func TestBuildBlockShouldReward(t *testing.T) {
require.NoError(err)

// Create a valid [AddPermissionlessValidatorTx]
builder, txSigner := env.factory.NewWallet(preFundedKeys[0])
builder, txSigner, feeCalc, err := env.factory.NewWallet(preFundedKeys[0])
require.NoError(err)
utx, err := builder.NewAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand All @@ -133,6 +136,7 @@ func TestBuildBlockShouldReward(t *testing.T) {
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
},
reward.PercentDenominator,
feeCalc,
common.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
Expand Down Expand Up @@ -251,13 +255,15 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) {
defer env.ctx.Lock.Unlock()

// Create a valid transaction
builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1])
builder, signer, feeCalc, err := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1])
require.NoError(err)
utx, err := builder.NewCreateChainTx(
testSubnet1.ID(),
nil,
constants.AVMID,
nil,
"chain name",
feeCalc,
)
require.NoError(err)
tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx)
Expand Down Expand Up @@ -320,7 +326,8 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
sk, err := bls.NewSecretKey()
require.NoError(err)

builder1, signer1 := env.factory.NewWallet(preFundedKeys[0])
builder1, signer1, feeCalc1, err := env.factory.NewWallet(preFundedKeys[0])
require.NoError(err)
utx1, err := builder1.NewAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand All @@ -342,6 +349,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
},
reward.PercentDenominator,
feeCalc1,
common.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
Expand All @@ -361,7 +369,8 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
sk, err = bls.NewSecretKey()
require.NoError(err)

builder2, signer2 := env.factory.NewWallet(preFundedKeys[2])
builder2, signer2, feeCalc2, err := env.factory.NewWallet(preFundedKeys[2])
require.NoError(err)
utx2, err := builder2.NewAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand All @@ -383,6 +392,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()},
},
reward.PercentDenominator,
feeCalc2,
common.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()},
Expand Down Expand Up @@ -426,13 +436,15 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) {
defer env.ctx.Lock.Unlock()

// Create a valid transaction
builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1])
builder, signer, feeCalc, err := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1])
require.NoError(err)
utx, err := builder.NewCreateChainTx(
testSubnet1.ID(),
nil,
constants.AVMID,
nil,
"chain name",
feeCalc,
)
require.NoError(err)
tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx)
Expand Down
7 changes: 5 additions & 2 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam

res.uptimes = uptime.NewManager(res.state, res.clk)
res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx)
res.factory = txstest.NewWalletFactory(res.ctx, res.config, res.state)
res.factory = txstest.NewWalletFactory(res.ctx, res.config, res.clk, res.state)

genesisID := res.state.GetLastAccepted()
res.backend = txexecutor.Backend{
Expand Down Expand Up @@ -236,7 +236,9 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam
func addSubnet(t *testing.T, env *environment) {
require := require.New(t)

builder, signer := env.factory.NewWallet(preFundedKeys[0])
builder, signer, feeCalc, err := env.factory.NewWallet(preFundedKeys[0])
require.NoError(err)

utx, err := builder.NewCreateSubnetTx(
&secp256k1fx.OutputOwners{
Threshold: 2,
Expand All @@ -246,6 +248,7 @@ func addSubnet(t *testing.T, env *environment) {
preFundedKeys[2].PublicKey().Address(),
},
},
feeCalc,
walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
Expand Down
5 changes: 4 additions & 1 deletion vms/platformvm/block/builder/standard_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ func TestAtomicTxImports(t *testing.T) {
}}},
}))

builder, signer := env.factory.NewWallet(recipientKey)
builder, signer, feeCalc, err := env.factory.NewWallet(recipientKey)
require.NoError(err)

utx, err := builder.NewImportTx(
env.ctx.XChainID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{recipientKey.PublicKey().Address()},
},
feeCalc,
)
require.NoError(err)
tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx)
Expand Down
17 changes: 15 additions & 2 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment
res.factory = txstest.NewWalletFactory(
res.ctx,
res.config,
res.clk,
res.state,
)
} else {
Expand All @@ -173,10 +174,12 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment
res.factory = txstest.NewWalletFactory(
res.ctx,
res.config,
res.clk,
res.mockedState,
)

// setup expectations strictly needed for environment creation
res.mockedState.EXPECT().GetTimestamp().Return(time.Time{}).AnyTimes() // to initialize createSubnet/BlockchainTx fee
res.mockedState.EXPECT().GetLastAccepted().Return(genesisBlkID).Times(1)
}

Expand Down Expand Up @@ -252,7 +255,11 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment
}

func addSubnet(env *environment) {
builder, signer := env.factory.NewWallet(preFundedKeys[0])
builder, signer, feeCalc, err := env.factory.NewWallet(preFundedKeys[0])
if err != nil {
panic(err)
}

utx, err := builder.NewCreateSubnetTx(
&secp256k1fx.OutputOwners{
Threshold: 2,
Expand All @@ -262,6 +269,7 @@ func addSubnet(env *environment) {
preFundedKeys[2].PublicKey().Address(),
},
},
feeCalc,
walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
Expand Down Expand Up @@ -505,7 +513,11 @@ func addPendingValidator(
rewardAddress ids.ShortID,
keys []*secp256k1.PrivateKey,
) (*txs.Tx, error) {
builder, signer := env.factory.NewWallet(keys...)
builder, signer, feeCalc, err := env.factory.NewWallet(keys...)
if err != nil {
return nil, err
}

utx, err := builder.NewAddValidatorTx(
&txs.Validator{
NodeID: nodeID,
Expand All @@ -518,6 +530,7 @@ func addPendingValidator(
Addrs: []ids.ShortID{rewardAddress},
},
reward.PercentDenominator,
feeCalc,
)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 6b8d844

Please sign in to comment.