test: unit test for GetSideEffectOperationsFromUndelegationPayouts

pull/3649/head
xiaohuo 4 years ago committed by Leo Chen
parent 211402fd30
commit 05e96f6566
  1. 1
      rosetta/services/tx_operation.go
  2. 75
      rosetta/services/tx_operation_test.go

@ -22,6 +22,7 @@ const (
SubAccountMetadataKey = "type"
Delegation = "delegation"
UnDelegation = "undelegation"
UndelegationPayout = "UndelegationPayout"
)
// GetNativeOperationsFromTransaction for one of the following transactions:

@ -243,6 +243,81 @@ func TestGetStakingOperationsFromDelegate(t *testing.T) {
}
}
func TestGetSideEffectOperationsFromUndelegationPayouts(t *testing.T) {
startingOperationIndex := int64(0)
undelegationPayouts := hmy.UndelegationPayouts{}
delegator := ethcommon.HexToAddress("0xB5f440B5c6215eEDc1b2E12b4b964fa31f7afa7d")
validator1 := ethcommon.HexToAddress("0x3b8DE43c8F30D3C387840681FED67783f93f1F94")
validator2 := ethcommon.HexToAddress("0xB5f440B5c6215eEDc1b2E12b4b964fa31f7afa7d")
undelegationPayouts[delegator] = make(map[ethcommon.Address]*big.Int)
undelegationPayouts[delegator][validator1] = new(big.Int).SetInt64(4000)
undelegationPayouts[delegator][validator2] = new(big.Int).SetInt64(5000)
operations, err := GetSideEffectOperationsFromUndelegationPayouts(undelegationPayouts, &startingOperationIndex)
if err != nil {
t.Fatal(err)
}
receiverAccId, err := newAccountIdentifier(delegator)
if err != nil {
t.Fatal(err)
}
reveiverSubAccId1, err := newAccountIdentifierWithSubAccount(delegator, validator1, map[string]interface{}{
SubAccountMetadataKey: UnDelegation,
})
if err != nil {
t.Fatal(err)
}
reveiverSubAccId2, err := newAccountIdentifierWithSubAccount(delegator, validator2, map[string]interface{}{
SubAccountMetadataKey: UnDelegation,
})
if err != nil {
t.Fatal(err)
}
refOperations := []*types.Operation{}
refOperations = append(refOperations, &types.Operation{
OperationIdentifier: &types.OperationIdentifier{Index: 0},
Type: UndelegationPayout,
Status: common.SuccessOperationStatus.Status,
Account: receiverAccId,
Amount: &types.Amount{
Value: fmt.Sprintf("9000"),
Currency: &common.NativeCurrency,
},
}, &types.Operation{
OperationIdentifier: &types.OperationIdentifier{Index: 1},
RelatedOperations: []*types.OperationIdentifier{
&types.OperationIdentifier{
Index: 0,
},
},
Type: UndelegationPayout,
Status: common.SuccessOperationStatus.Status,
Account: reveiverSubAccId1,
Amount: &types.Amount{
Value: fmt.Sprintf("-4000"),
Currency: &common.NativeCurrency,
},
}, &types.Operation{
OperationIdentifier: &types.OperationIdentifier{Index: 2},
RelatedOperations: []*types.OperationIdentifier{
&types.OperationIdentifier{
Index: 0,
},
},
Type: UndelegationPayout,
Status: common.SuccessOperationStatus.Status,
Account: reveiverSubAccId2,
Amount: &types.Amount{
Value: fmt.Sprintf("-5000"),
Currency: &common.NativeCurrency,
},
})
if !reflect.DeepEqual(refOperations, operations) {
t.Errorf("Expected operations to be %v not %v", refOperations, operations)
}
}
func TestGetStakingOperationsFromUndelegate(t *testing.T) {
gasLimit := uint64(1e18)
senderKey, err := crypto.GenerateKey()

Loading…
Cancel
Save