diff --git a/vms/platformvm/add_default_subnet_delegator_tx.go b/vms/platformvm/add_default_subnet_delegator_tx.go index 3012d84..9881652 100644 --- a/vms/platformvm/add_default_subnet_delegator_tx.go +++ b/vms/platformvm/add_default_subnet_delegator_tx.go @@ -128,7 +128,7 @@ func (tx *addDefaultSubnetDelegatorTx) SemanticVerify(db database.Database) (*ve // The account if this block's proposal is committed and the validator is // added to the pending validator set. (Increase the account's nonce; // decrease its balance.) - newAccount, err := account.Remove(0, tx.Nonce) // Remove also removes the fee + newAccount, err := account.Remove(tx.Wght, tx.Nonce) // Remove also removes the fee if err != nil { return nil, nil, nil, nil, permError{err} } diff --git a/vms/platformvm/add_default_subnet_delegator_tx_test.go b/vms/platformvm/add_default_subnet_delegator_tx_test.go index 65a0a71..9380001 100644 --- a/vms/platformvm/add_default_subnet_delegator_tx_test.go +++ b/vms/platformvm/add_default_subnet_delegator_tx_test.go @@ -386,4 +386,52 @@ func TestAddDefaultSubnetDelegatorTxSemanticVerify(t *testing.T) { t.Fatal("should have failed verification because payer account has no $AVA to pay fee") } txFee = txFeeSaved // Reset tx fee + + // Case 8: fail verification for spending more funds than it has + tx, err = vm.newAddDefaultSubnetDelegatorTx( + defaultNonce+1, + defaultBalance*2, // weight + uint64(defaultValidateStartTime.Unix()), // start time + uint64(defaultValidateEndTime.Unix()), // end time + defaultKey.PublicKey().Address(), // node ID + defaultKey.PublicKey().Address(), // destination + testNetworkID, // network ID + defaultKey, // tx fee payer + ) + if err != nil { + t.Fatal(err) + } + _, _, _, _, err = tx.SemanticVerify(vm.DB) + if err == nil { + t.Fatal("should have failed verification because payer account spent twice the account's balance") + } + + // Case 9: Confirm balance is correct + tx, err = vm.newAddDefaultSubnetDelegatorTx( + defaultNonce+1, + defaultStakeAmount, // weight + uint64(defaultValidateStartTime.Unix()), // start time + uint64(defaultValidateEndTime.Unix()), // end time + defaultKey.PublicKey().Address(), // node ID + defaultKey.PublicKey().Address(), // destination + testNetworkID, // network ID + defaultKey, // tx fee payer + ) + if err != nil { + t.Fatal(err) + } + + onCommitDB, _, _, _, err := tx.SemanticVerify(vm.DB) + if err != nil { + t.Fatal(err) + } + account, err := tx.vm.getAccount(onCommitDB, defaultKey.PublicKey().Address()) + if err != nil { + t.Fatal(err) + } + balance := account.Balance + + if balance != defaultBalance-(defaultStakeAmount+txFee) { + t.Fatalf("balance was not updated correctly after subnet delegator tx") + } }