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

[vms/platformvm] Use wallet sdk in txstest.Builder #2751

Merged
merged 94 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
f5ff8d6
spend cleanup
abi87 Feb 19, 2024
26a9e31
Merge branch 'master' into p-chain_spend_cleanup
abi87 Feb 19, 2024
7f594ea
repackaged signer from wallet to pchain txs subpackage
abi87 Feb 19, 2024
89da2ba
introduced wallet signer visitor in pchain txs builder subpackage
abi87 Feb 20, 2024
e26bec9
drop signers from utxos.Spend handler
abi87 Feb 20, 2024
dd17dbb
moved wallet builder backend to pchain
abi87 Feb 20, 2024
0904787
some more repackaging
abi87 Feb 20, 2024
2087443
wip: chaining p-chain txbuilder with wallet builder and signer
abi87 Feb 20, 2024
2ef66ea
nit
abi87 Feb 21, 2024
0cd2d7e
Merge branch 'master' into p-chain_spend_cleanup
abi87 Feb 21, 2024
95d64cc
wip: some more chaining p-chain txbuilder with wallet builder and signer
abi87 Feb 21, 2024
131c198
txbuilder constructor cleanup
abi87 Feb 21, 2024
979e30d
removed utxos Spend and Authorize
abi87 Feb 21, 2024
566b09b
moved backends package to wallet
abi87 Feb 21, 2024
1b22091
nit
abi87 Feb 21, 2024
f7d288c
nits
abi87 Feb 21, 2024
fa0eb5a
repackaged wallet backend for P-chain
abi87 Feb 21, 2024
4405a2e
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Feb 21, 2024
480fb45
consolidated backend implementation
abi87 Feb 21, 2024
30498e7
some more cleanup
abi87 Feb 21, 2024
1881282
nits
abi87 Feb 21, 2024
fca9d28
fixed create chain tx fee
abi87 Feb 21, 2024
0f24a1a
fixed UTs
abi87 Feb 21, 2024
ba8e792
Merge branch 'master' into p-chain_wallet_backends
abi87 Feb 22, 2024
d2d6aec
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Feb 22, 2024
5aa5932
some more fixes
abi87 Feb 22, 2024
20a7c41
Merge branch 'p-chain_spend_cleanup' of github.com:ava-labs/avalanche…
abi87 Feb 22, 2024
3b6b5f5
Merge branch 'master' into p-chain_wallet_backends
abi87 Feb 25, 2024
655e402
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Feb 25, 2024
ebc1b50
minor renaming
abi87 Feb 26, 2024
952ed47
Merge branch 'master' into p-chain_wallet_backends
abi87 Feb 29, 2024
c050a42
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Feb 29, 2024
2aa4b70
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 4, 2024
4b47e03
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 4, 2024
4aedae5
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 5, 2024
a92b693
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 6, 2024
e418d7e
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 6, 2024
f1e5a44
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 7, 2024
0d5a1af
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 7, 2024
08def6a
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 11, 2024
e9860dc
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 11, 2024
b01a2d2
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 11, 2024
eb59fda
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 11, 2024
a56a753
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 12, 2024
2039a84
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 12, 2024
4c5787e
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 13, 2024
a581616
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 13, 2024
9ac3a33
Merge branch 'master' into p-chain_wallet_backends
abi87 Mar 18, 2024
2c3f2a5
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
abi87 Mar 18, 2024
16cf7c4
cleanup
StephenButtolph Mar 18, 2024
51729d9
nit
StephenButtolph Mar 18, 2024
6772d28
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
StephenButtolph Mar 18, 2024
9481ff7
nit
StephenButtolph Mar 19, 2024
ade5178
fix merge
StephenButtolph Mar 19, 2024
ba48394
nit
StephenButtolph Mar 19, 2024
c6f7143
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
StephenButtolph Mar 19, 2024
6de663b
save
StephenButtolph Mar 19, 2024
6c9004d
nit
StephenButtolph Mar 19, 2024
318be91
nit
StephenButtolph Mar 19, 2024
41f1405
nit
StephenButtolph Mar 19, 2024
edbfd16
nit
StephenButtolph Mar 19, 2024
bc5b5e0
nit
StephenButtolph Mar 19, 2024
264706d
Merge branch 'p-chain_wallet_backends' into p-chain_spend_cleanup
StephenButtolph Mar 19, 2024
b2d11ce
nit
StephenButtolph Mar 19, 2024
ff6f721
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 19, 2024
48bd901
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 20, 2024
79d8b2d
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 21, 2024
fc5cc77
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 22, 2024
064a486
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 22, 2024
90456d5
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 25, 2024
5d13597
nits (#2861)
dhrubabasu Mar 25, 2024
f45afe9
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 26, 2024
f57a91a
Merge branch 'master' into p-chain_spend_cleanup
dhrubabasu Mar 26, 2024
77be9e9
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 27, 2024
d695437
nits (#2874)
dhrubabasu Mar 27, 2024
fe8c795
remove config from backend
dhrubabasu Mar 27, 2024
3f7291f
nit
dhrubabasu Mar 27, 2024
1cddffc
nit
dhrubabasu Mar 27, 2024
af093c9
nit
dhrubabasu Mar 27, 2024
b0ec09b
nit
dhrubabasu Mar 27, 2024
4cb5f9e
Merge branch 'master' into p-chain_spend_cleanup
dhrubabasu Mar 27, 2024
508d742
Merge branch 'master' into p-chain_spend_cleanup
dhrubabasu Mar 27, 2024
d8f04ba
Merge branch 'master' into p-chain_spend_cleanup
abi87 Mar 28, 2024
f8af011
nit to restore stakers order in UT
abi87 Mar 28, 2024
6fd25ec
nit
abi87 Mar 28, 2024
42b556d
nit
dhrubabasu Mar 28, 2024
0d157f8
nits
dhrubabasu Mar 28, 2024
cd97be6
nit
dhrubabasu Mar 28, 2024
cd105df
`txstest`
dhrubabasu Mar 28, 2024
daeb16a
nit
dhrubabasu Mar 28, 2024
5e2e788
reduce diff
dhrubabasu Mar 28, 2024
a0cc76b
nits
dhrubabasu Mar 28, 2024
8c91bb3
nit
dhrubabasu Mar 28, 2024
069cf17
Merge branch 'master' into p-chain_spend_cleanup
dhrubabasu Mar 28, 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
95 changes: 68 additions & 27 deletions vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"

blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor"
txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
Expand All @@ -44,8 +46,6 @@ func TestBuildBlockBasic(t *testing.T) {
nil,
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down Expand Up @@ -110,16 +110,31 @@ func TestBuildBlockShouldReward(t *testing.T) {

// Create a valid [AddPermissionlessValidatorTx]
tx, err := env.txBuilder.NewAddPermissionlessValidatorTx(
defaultValidatorStake,
uint64(validatorStartTime.Unix()),
uint64(validatorEndTime.Unix()),
nodeID,
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: nodeID,
Start: uint64(validatorStartTime.Unix()),
End: uint64(validatorEndTime.Unix()),
Wght: defaultValidatorStake,
},
Subnet: constants.PrimaryNetworkID,
},
signer.NewProofOfPossession(sk),
preFundedKeys[0].PublicKey().Address(),
env.ctx.AVAXAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
},
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
},
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
common.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
}),
)
require.NoError(err)
txID := tx.ID()
Expand Down Expand Up @@ -239,8 +254,6 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) {
nil,
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down Expand Up @@ -302,16 +315,31 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
require.NoError(err)

tx1, err := env.txBuilder.NewAddPermissionlessValidatorTx(
defaultValidatorStake,
uint64(now.Unix()),
uint64(validatorEndTime.Unix()),
ids.GenerateTestNodeID(),
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: ids.GenerateTestNodeID(),
Start: uint64(now.Unix()),
End: uint64(validatorEndTime.Unix()),
Wght: defaultValidatorStake,
},
Subnet: constants.PrimaryNetworkID,
},
signer.NewProofOfPossession(sk),
preFundedKeys[0].PublicKey().Address(),
env.ctx.AVAXAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
},
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
},
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
common.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
}),
)
require.NoError(err)
require.NoError(env.mempool.Add(tx1))
Expand All @@ -326,16 +354,31 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
require.NoError(err)

tx2, err := env.txBuilder.NewAddPermissionlessValidatorTx(
defaultValidatorStake,
uint64(now.Unix()),
uint64(validator2EndTime.Unix()),
ids.GenerateTestNodeID(),
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: ids.GenerateTestNodeID(),
Start: uint64(now.Unix()),
End: uint64(validator2EndTime.Unix()),
Wght: defaultValidatorStake,
},
Subnet: constants.PrimaryNetworkID,
},
signer.NewProofOfPossession(sk),
preFundedKeys[2].PublicKey().Address(),
env.ctx.AVAXAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()},
},
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()},
},
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[2]},
preFundedKeys[2].PublicKey().Address(),
nil,
common.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()},
}),
)
require.NoError(err)
require.NoError(env.mempool.Add(tx2))
Expand Down Expand Up @@ -380,8 +423,6 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) {
nil,
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down
35 changes: 18 additions & 17 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest"
"github.com/ava-labs/avalanchego/vms/platformvm/utxo"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor"
txbuilder "github.com/ava-labs/avalanchego/vms/platformvm/txs/builder"
txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators"
walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)

const (
Expand Down Expand Up @@ -116,8 +117,8 @@ type environment struct {
state state.State
atomicUTXOs avax.AtomicUTXOManager
uptimes uptime.Manager
utxosHandler utxo.Handler
txBuilder txbuilder.Builder
utxosVerifier utxo.Verifier
txBuilder *txstest.Builder
backend txexecutor.Backend
}

Expand Down Expand Up @@ -151,16 +152,12 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam

res.atomicUTXOs = avax.NewAtomicUTXOManager(res.ctx.SharedMemory, txs.Codec)
res.uptimes = uptime.NewManager(res.state, res.clk)
res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.fx)
res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx)

res.txBuilder = txbuilder.New(
res.txBuilder = txstest.NewBuilder(
res.ctx,
res.config,
res.clk,
res.fx,
res.state,
res.atomicUTXOs,
res.utxosHandler,
)

genesisID := res.state.GetLastAccepted()
Expand All @@ -170,7 +167,7 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam
Clk: res.clk,
Bootstrapped: res.isBootstrapped,
Fx: res.fx,
FlowChecker: res.utxosHandler,
FlowChecker: res.utxosVerifier,
Uptimes: res.uptimes,
Rewards: rewardsCalc,
}
Expand Down Expand Up @@ -247,15 +244,19 @@ func addSubnet(t *testing.T, env *environment) {
// Create a subnet
var err error
testSubnet1, err = env.txBuilder.NewCreateSubnetTx(
2, // threshold; 2 sigs from keys[0], keys[1], keys[2] needed to add validator to this subnet
[]ids.ShortID{ // control keys
preFundedKeys[0].PublicKey().Address(),
preFundedKeys[1].PublicKey().Address(),
preFundedKeys[2].PublicKey().Address(),
&secp256k1fx.OutputOwners{
Threshold: 2,
Addrs: []ids.ShortID{
preFundedKeys[0].PublicKey().Address(),
preFundedKeys[1].PublicKey().Address(),
preFundedKeys[2].PublicKey().Address(),
},
},
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
}),
)
require.NoError(err)

Expand Down
7 changes: 4 additions & 3 deletions vms/platformvm/block/builder/standard_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ func TestAtomicTxImports(t *testing.T) {

tx, err := env.txBuilder.NewImportTx(
env.ctx.XChainID,
recipientKey.PublicKey().Address(),
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{recipientKey.PublicKey().Address()},
},
[]*secp256k1.PrivateKey{recipientKey},
ids.ShortEmpty, // change addr
nil,
)
require.NoError(err)

Expand Down
61 changes: 31 additions & 30 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest"
"github.com/ava-labs/avalanchego/vms/platformvm/utxo"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

p_tx_builder "github.com/ava-labs/avalanchego/vms/platformvm/txs/builder"
pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators"
walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)

const (
Expand Down Expand Up @@ -128,8 +129,8 @@ type environment struct {
mockedState *state.MockState
atomicUTXOs avax.AtomicUTXOManager
uptimes uptime.Manager
utxosHandler utxo.Handler
txBuilder p_tx_builder.Builder
utxosVerifier utxo.Verifier
txBuilder *txstest.Builder
backend *executor.Backend
}

Expand Down Expand Up @@ -157,29 +158,22 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment
if ctrl == nil {
res.state = defaultState(res.config, res.ctx, res.baseDB, rewardsCalc)
res.uptimes = uptime.NewManager(res.state, res.clk)
res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.fx)
res.txBuilder = p_tx_builder.New(
res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx)
res.txBuilder = txstest.NewBuilder(
res.ctx,
res.config,
res.clk,
res.fx,
res.state,
res.atomicUTXOs,
res.utxosHandler,
)
} else {
genesisBlkID = ids.GenerateTestID()
res.mockedState = state.NewMockState(ctrl)
res.uptimes = uptime.NewManager(res.mockedState, res.clk)
res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.fx)
res.txBuilder = p_tx_builder.New(
res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx)

res.txBuilder = txstest.NewBuilder(
res.ctx,
res.config,
res.clk,
res.fx,
res.mockedState,
res.atomicUTXOs,
res.utxosHandler,
)

// setup expectations strictly needed for environment creation
Expand All @@ -192,7 +186,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment
Clk: res.clk,
Bootstrapped: res.isBootstrapped,
Fx: res.fx,
FlowChecker: res.utxosHandler,
FlowChecker: res.utxosVerifier,
Uptimes: res.uptimes,
Rewards: rewardsCalc,
}
Expand Down Expand Up @@ -261,15 +255,19 @@ func addSubnet(env *environment) {
// Create a subnet
var err error
testSubnet1, err = env.txBuilder.NewCreateSubnetTx(
2, // threshold; 2 sigs from keys[0], keys[1], keys[2] needed to add validator to this subnet
[]ids.ShortID{ // control keys
preFundedKeys[0].PublicKey().Address(),
preFundedKeys[1].PublicKey().Address(),
preFundedKeys[2].PublicKey().Address(),
&secp256k1fx.OutputOwners{
Threshold: 2,
Addrs: []ids.ShortID{
preFundedKeys[0].PublicKey().Address(),
preFundedKeys[1].PublicKey().Address(),
preFundedKeys[2].PublicKey().Address(),
},
},
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()},
}),
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -495,15 +493,18 @@ func addPendingValidator(
keys []*secp256k1.PrivateKey,
) (*txs.Tx, error) {
addPendingValidatorTx, err := env.txBuilder.NewAddValidatorTx(
env.config.MinValidatorStake,
uint64(startTime.Unix()),
uint64(endTime.Unix()),
nodeID,
rewardAddress,
&txs.Validator{
NodeID: nodeID,
Start: uint64(startTime.Unix()),
End: uint64(endTime.Unix()),
Wght: env.config.MinValidatorStake,
},
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{rewardAddress},
},
reward.PercentDenominator,
keys,
ids.ShortEmpty,
nil,
)
if err != nil {
return nil, err
Expand Down
Loading
Loading