Skip to content

Commit

Permalink
[test] refs fibercrypto#136 - Add test for LocalWallet::Spend.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiD2ta committed Nov 8, 2019
1 parent 8acecba commit eb4bdc4
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/coin/skycoin/models/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,3 +1095,62 @@ func TestLocalWalletSendFromAddress(t *testing.T) {
require.Equal(t, util.FormatCoins(uint64(sky), 10), util.FormatCoins(uint64(val), 10))
require.Equal(t, crtTxn.Transaction.TxID, ret.GetId())
}

func TestLocalWalletSpend(t *testing.T) {
CleanGlobalMock()
destinationAddress := testutil.MakeAddress()
changeAddress := (testutil.MakeAddress()).String()
sky := 500
wlt := makeLocalWallet(t)

toAddr := &SkycoinTransactionOutput{
skyOut: readable.TransactionOutput{
Address: destinationAddress.String(),
Coins: strconv.Itoa(sky),
Hours: uint64(250),
},
}
chgAddr := &SkycoinAddress{
address: changeAddress,
}

opt := NewTransferOptions()
opt.SetValue("BurnFactor", "0.5")
opt.SetValue("CoinHoursSelectionType", "auto")

req := api.CreateTransactionRequest{
IgnoreUnconfirmed: false,
HoursSelection: api.HoursSelection{
Type: "auto",
Mode: "share",
ShareFactor: "0.5",
},
ChangeAddress: &changeAddress,
To: []api.Receiver{
api.Receiver{
Address: destinationAddress.String(),
Coins: strconv.Itoa(sky),
},
},
}

hash := testutil.RandSHA256(t)
txn := coin.Transaction{
Length: 100,
Type: 0,
InnerHash: hash,
}
crtTxn, err := api.NewCreateTransactionResponse(&txn, nil)
require.NoError(t, err)
crtTxn.Transaction.Fee = "500"

mockSkyApiCreateTransaction(global_mock, &req, crtTxn)

ret, err := wlt.Spend(nil, []core.TransactionOutput{toAddr}, chgAddr, opt)
require.NoError(t, err)
require.NotNil(t, ret)
val, err := ret.ComputeFee(CoinHour)
require.NoError(t, err)
require.Equal(t, uint64(sky), val)
require.Equal(t, crtTxn.Transaction.TxID, ret.GetId())
}

0 comments on commit eb4bdc4

Please sign in to comment.