mirror of https://github.com/poanetwork/gecko.git
Merge pull request #77 from ava-labs/patch-add-default-subnet-delegator-tx
Patch add default subnet delegator tx
This commit is contained in:
commit
22cccd02f9
|
@ -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}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue