Skip to content

Commit

Permalink
P-Chain tx builder refactor (ava-labs#1595)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
abi87 and StephenButtolph authored Jun 29, 2022
1 parent 55b4566 commit 13c6006
Show file tree
Hide file tree
Showing 40 changed files with 1,165 additions and 1,027 deletions.
57 changes: 0 additions & 57 deletions vms/platformvm/add_delegator_tx.go

This file was deleted.

38 changes: 19 additions & 19 deletions vms/platformvm/add_delegator_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func TestAddDelegatorTxSyntacticVerify(t *testing.T) {
vm, _, _ := defaultVM()
vm, _, _, _ := defaultVM()
vm.ctx.Lock.Lock()
defer func() {
if err := vm.Shutdown(); err != nil {
Expand All @@ -42,7 +42,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) {
}

// Case: Wrong network ID
tx, err := vm.newAddDelegatorTx(
tx, err := vm.txBuilder.NewAddDelegatorTx(
vm.MinDelegatorStake,
uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()),
Expand All @@ -65,7 +65,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) {
}

// Case: Valid
if tx, err = vm.newAddDelegatorTx(
if tx, err = vm.txBuilder.NewAddDelegatorTx(
vm.MinDelegatorStake,
uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()),
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestAddDelegatorTxExecute(t *testing.T) {
// [addMinStakeValidator] adds a new validator to the primary network's
// pending validator set with the minimum staking amount
addMinStakeValidator := func(vm *VM) {
tx, err := vm.newAddValidatorTx(
tx, err := vm.txBuilder.NewAddValidatorTx(
vm.MinValidatorStake, // stake amount
newValidatorStartTime, // start time
newValidatorEndTime, // end time
Expand All @@ -124,7 +124,7 @@ func TestAddDelegatorTxExecute(t *testing.T) {
// [addMaxStakeValidator] adds a new validator to the primary network's
// pending validator set with the maximum staking amount
addMaxStakeValidator := func(vm *VM) {
tx, err := vm.newAddValidatorTx(
tx, err := vm.txBuilder.NewAddValidatorTx(
vm.MaxValidatorStake, // stake amount
newValidatorStartTime, // start time
newValidatorEndTime, // end time
Expand All @@ -148,7 +148,7 @@ func TestAddDelegatorTxExecute(t *testing.T) {
}
}

freshVM, _, _ := defaultVM()
freshVM, _, _, _ := defaultVM()
currentTimestamp := freshVM.internalState.GetTimestamp()

type test struct {
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestAddDelegatorTxExecute(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
vm, _, _ := defaultVM()
vm, _, _, _ := defaultVM()
vm.ApricotPhase3Time = tt.AP3Time

vm.ctx.Lock.Lock()
Expand All @@ -323,7 +323,7 @@ func TestAddDelegatorTxExecute(t *testing.T) {
vm.ctx.Lock.Unlock()
}()

tx, err := vm.newAddDelegatorTx(
tx, err := vm.txBuilder.NewAddDelegatorTx(
tt.stakeAmount,
tt.startTime,
tt.endTime,
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestAddDelegatorTxExecute(t *testing.T) {
func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
assert := assert.New(t)

vm, _, _ := defaultVM()
vm, _, _, _ := defaultVM()
vm.ctx.Lock.Lock()
defer func() {
err := vm.Shutdown()
Expand All @@ -375,7 +375,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
id := key.PublicKey().Address()

// create valid tx
addValidatorTx, err := vm.newAddValidatorTx(
addValidatorTx, err := vm.txBuilder.NewAddValidatorTx(
vm.MinValidatorStake,
uint64(validatorStartTime.Unix()),
uint64(validatorEndTime.Unix()),
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration)

// create valid tx
addFirstDelegatorTx, err := vm.newAddDelegatorTx(
addFirstDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
4*vm.MinValidatorStake, // maximum amount of stake this delegator can provide
uint64(firstDelegatorStartTime.Unix()),
uint64(firstDelegatorEndTime.Unix()),
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
vm.clock.Set(secondDelegatorStartTime.Add(-10 * syncBound))

// create valid tx
addSecondDelegatorTx, err := vm.newAddDelegatorTx(
addSecondDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
vm.MinDelegatorStake,
uint64(secondDelegatorStartTime.Unix()),
uint64(secondDelegatorEndTime.Unix()),
Expand All @@ -464,7 +464,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration)

// create valid tx
addThirdDelegatorTx, err := vm.newAddDelegatorTx(
addThirdDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
vm.MinDelegatorStake,
uint64(thirdDelegatorStartTime.Unix()),
uint64(thirdDelegatorEndTime.Unix()),
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
assert := assert.New(t)

vm, _, _ := defaultVM()
vm, _, _, _ := defaultVM()
vm.ApricotPhase3Time = test.ap3Time

vm.ctx.Lock.Lock()
Expand All @@ -540,7 +540,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
changeAddr := keys[0].PublicKey().Address()

// create valid tx
addValidatorTx, err := vm.newAddValidatorTx(
addValidatorTx, err := vm.txBuilder.NewAddValidatorTx(
validatorStake,
uint64(validatorStartTime.Unix()),
uint64(validatorEndTime.Unix()),
Expand All @@ -563,7 +563,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
verifyAndAcceptProposalCommitment(assert, addValidatorBlock)

// create valid tx
addFirstDelegatorTx, err := vm.newAddDelegatorTx(
addFirstDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
delegator1Stake,
uint64(delegator1StartTime.Unix()),
uint64(delegator1EndTime.Unix()),
Expand All @@ -585,7 +585,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
verifyAndAcceptProposalCommitment(assert, addFirstDelegatorBlock)

// create valid tx
addSecondDelegatorTx, err := vm.newAddDelegatorTx(
addSecondDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
delegator2Stake,
uint64(delegator2StartTime.Unix()),
uint64(delegator2EndTime.Unix()),
Expand All @@ -607,7 +607,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
verifyAndAcceptProposalCommitment(assert, addSecondDelegatorBlock)

// create valid tx
addThirdDelegatorTx, err := vm.newAddDelegatorTx(
addThirdDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
delegator3Stake,
uint64(delegator3StartTime.Unix()),
uint64(delegator3EndTime.Unix()),
Expand All @@ -629,7 +629,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
verifyAndAcceptProposalCommitment(assert, addThirdDelegatorBlock)

// create valid tx
addFourthDelegatorTx, err := vm.newAddDelegatorTx(
addFourthDelegatorTx, err := vm.txBuilder.NewAddDelegatorTx(
delegator4Stake,
uint64(delegator4StartTime.Unix()),
uint64(delegator4EndTime.Unix()),
Expand Down
61 changes: 0 additions & 61 deletions vms/platformvm/add_subnet_validator_tx.go

This file was deleted.

Loading

0 comments on commit 13c6006

Please sign in to comment.