Skip to content

Commit

Permalink
[test] refs fibercrypto#136 - Use NewCreateTransactionResponse in Tes…
Browse files Browse the repository at this point in the history
…tRemoteWallet tests.

Tests:
- TestRemoteWalletTransfer
- TestRemoteWalletSendFromAddress
  • Loading branch information
AntiD2ta committed Oct 28, 2019
1 parent 648860f commit 0153ed6
Showing 1 changed file with 25 additions and 39 deletions.
64 changes: 25 additions & 39 deletions src/coin/skycoin/models/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package skycoin
import (
"io/ioutil"
"math"
"strings"
"strconv"
"strings"
"testing"

"github.com/fibercrypto/FiberCryptoWallet/src/coin/skycoin/testsuite"
Expand Down Expand Up @@ -317,17 +317,13 @@ func TestRemoteWalletTransfer(t *testing.T) {
CreateTransactionRequest: req,
}

crtTxn := &api.CreateTransactionResponse{
Transaction: api.CreatedTransaction{
Fee: "500",
InnerHash: hash.Hex(),
},
}
tx := &coin.Transaction{
txn := coin.Transaction{
Length: 100,
Type: 0,
InnerHash: hash,
}
b, _ := tx.Serialize()
crtTxn.Transaction.TxID = cipher.SumSHA256(b).Hex()
crtTxn, err := api.NewCreateTransactionResponse(&txn, nil)
crtTxn.Transaction.Fee = "500"

global_mock.On("WalletCreateTransaction", wreq).Return(
crtTxn,
Expand All @@ -338,12 +334,13 @@ func TestRemoteWalletTransfer(t *testing.T) {
poolSection: PoolSection,
}

txn, err := wlt.Transfer(addr, uint64(sky*1e6), opt)
ret, err := wlt.Transfer(addr, uint64(sky*1e6), opt)
require.Nil(t, err)
val, err := txn.ComputeFee(CoinHour)
require.NotNil(t, ret)
val, err := ret.ComputeFee(CoinHour)
require.Nil(t, err)
require.Equal(t, uint64(sky), val)
require.Equal(t, crtTxn.Transaction.TxID, txn.GetId())
require.Equal(t, crtTxn.Transaction.TxID, ret.GetId())

}

Expand Down Expand Up @@ -396,13 +393,6 @@ func TestRemoteWalletSendFromAddress(t *testing.T) {
CreateTransactionRequest: req1,
}

crtTxn1 := &api.CreateTransactionResponse{
Transaction: api.CreatedTransaction{
Fee: strconv.Itoa(sky),
InnerHash: hash.Hex(),
},
}

opt2 := NewTransferOptions()
opt2.AddKeyValue("BurnFactor", "0.5")
opt2.AddKeyValue("CoinHoursSelectionType", "manual")
Expand All @@ -429,50 +419,46 @@ func TestRemoteWalletSendFromAddress(t *testing.T) {
CreateTransactionRequest: req2,
}

crtTxn2 := &api.CreateTransactionResponse{
Transaction: api.CreatedTransaction{
Fee: strconv.Itoa(sky),
InnerHash: hash.Hex(),
},
}

tx := &coin.Transaction{
txn := coin.Transaction{
Length: 100,
Type: 0,
InnerHash: hash,
}
b, _ := tx.Serialize()
crtTxn1.Transaction.TxID = cipher.SumSHA256(b).Hex()
crtTxn2.Transaction.TxID = crtTxn1.Transaction.TxID
crtTxn, err := api.NewCreateTransactionResponse(&txn, nil)
crtTxn.Transaction.Fee = strconv.Itoa(sky)

global_mock.On("WalletCreateTransaction", wreq1).Return(
crtTxn1,
crtTxn,
nil)
global_mock.On("WalletCreateTransaction", wreq2).Return(
crtTxn2,
crtTxn,
nil)

wlt1 := &RemoteWallet{
Id: "wallet1",
poolSection: PoolSection,
}

txn, err := wlt1.SendFromAddress([]core.Address{fromAddr}, []core.TransactionOutput{toAddr}, chgAddr, opt1)
ret, err := wlt1.SendFromAddress([]core.Address{fromAddr}, []core.TransactionOutput{toAddr}, chgAddr, opt1)
require.Nil(t, err)
val, err := txn.ComputeFee(CoinHour)
require.NotNil(t, ret)
val, err := ret.ComputeFee(CoinHour)
require.Nil(t, err)
require.Equal(t, util.FormatCoins(uint64(sky), 10), util.FormatCoins(uint64(val), 10))
require.Equal(t, crtTxn1.Transaction.TxID, txn.GetId())
require.Equal(t, crtTxn.Transaction.TxID, ret.GetId())

wlt2 := &RemoteWallet{
Id: "wallet2",
poolSection: PoolSection,
}

txn, err = wlt2.SendFromAddress([]core.Address{fromAddr}, []core.TransactionOutput{toAddr}, chgAddr, opt2)
ret, err = wlt2.SendFromAddress([]core.Address{fromAddr}, []core.TransactionOutput{toAddr}, chgAddr, opt2)
require.Nil(t, err)
val, err = txn.ComputeFee(CoinHour)
require.NotNil(t, ret)
val, err = ret.ComputeFee(CoinHour)
require.Nil(t, err)
require.Equal(t, util.FormatCoins(uint64(sky), 10), util.FormatCoins(uint64(val), 10))
require.Equal(t, crtTxn2.Transaction.TxID, txn.GetId())
require.Equal(t, crtTxn.Transaction.TxID, ret.GetId())
}

func TestRemoteWalletGenAddresses(t *testing.T) {
Expand Down

0 comments on commit 0153ed6

Please sign in to comment.