Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiquan911 committed May 30, 2019
1 parent c118cb6 commit 20e0246
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
30 changes: 24 additions & 6 deletions openwtester/transaction_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestWalletManager_GetTransactionByWxID(t *testing.T) {
func TestWalletManager_GetAssetsAccountBalance(t *testing.T) {
tm := testInitWalletManager()
walletID := "WGVsUfTTVaCwAMRTqeJiDQsZ3vrWp9DzMA"
accountID := "CbnmpvJNsUjtEMRoy5Nf5FGTyfjLbke8FuKjKtEUc7fs"
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"

balance, err := tm.GetAssetsAccountBalance(testApp, walletID, accountID)
if err != nil {
Expand All @@ -121,13 +121,31 @@ func TestWalletManager_GetAssetsAccountTokenBalance(t *testing.T) {
walletID := "WGVsUfTTVaCwAMRTqeJiDQsZ3vrWp9DzMA"
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"

//contract := openwallet.SmartContract{
// Address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
// Symbol: "TRX",
// Name: "Tether USD",
// Token: "USDT",
// Decimals: 6,
// Protocol: "trc20",
//}

//contract := openwallet.SmartContract{
// Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
// Symbol: "TRX",
// Name: "TRONdice",
// Token: "DICE",
// Decimals: 6,
// Protocol: "trc20",
//}

contract := openwallet.SmartContract{
Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
Address: "1002000",
Symbol: "TRX",
Name: "TRONdice",
Token: "DICE",
Decimals: 6,
Protocol: "trc20",
Name: "BitTorrent",
Token: "BTT",
Decimals: 0,
Protocol: "trc10",
}

balance, err := tm.GetAssetsAccountTokenBalance(testApp, walletID, accountID, contract)
Expand Down
38 changes: 28 additions & 10 deletions openwtester/transcation_assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,20 @@ func TestTransfer_TRC20(t *testing.T) {
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
to := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"

//contract := openwallet.SmartContract{
// Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
// Symbol: "TRX",
// Name: "TRONdice",
// Token: "DICE",
// Decimals: 6,
// Protocol: "trc20",
//}

contract := openwallet.SmartContract{
Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
Address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
Symbol: "TRX",
Name: "TRONdice",
Token: "DICE",
Name: "Tether USD",
Token: "USDT",
Decimals: 6,
Protocol: "trc20",
}
Expand All @@ -170,7 +179,7 @@ func TestTransfer_TRC20(t *testing.T) {

testGetAssetsAccountTokenBalance(tm, walletID, accountID, contract)

rawTx, err := testCreateTransactionStep(tm, walletID, accountID, to, "0.002", "", &contract)
rawTx, err := testCreateTransactionStep(tm, walletID, accountID, to, "1.5", "", &contract)
if err != nil {
return
}
Expand Down Expand Up @@ -244,7 +253,7 @@ func TestSummary(t *testing.T) {
testGetAssetsAccountBalance(tm, walletID, accountID)

rawTxArray, err := testCreateSummaryTransactionStep(tm, walletID, accountID,
summaryAddress, "0.01", "0.01", "",
summaryAddress, "", "", "",
0, 100, nil, nil)
if err != nil {
log.Errorf("CreateSummaryTransaction failed, unexpected error: %v", err)
Expand Down Expand Up @@ -345,15 +354,24 @@ func TestSummary_TRC20(t *testing.T) {

feesSupport := openwallet.FeesSupportAccount{
AccountID: "5Tm3sqFap329wj3Du4DVXMkjAe85FVH3MaB6HSV8joj1",
//FixSupportAmount: "1",
FeesSupportScale: "1.3",
FixSupportAmount: "0.5",
//FeesSupportScale: "1.3",
}

//contract := openwallet.SmartContract{
// Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
// Symbol: "TRX",
// Name: "TRONdice",
// Token: "DICE",
// Decimals: 6,
// Protocol: "trc20",
//}

contract := openwallet.SmartContract{
Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
Address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
Symbol: "TRX",
Name: "TRONdice",
Token: "DICE",
Name: "Tether USD",
Token: "USDT",
Decimals: 6,
Protocol: "trc20",
}
Expand Down
4 changes: 2 additions & 2 deletions tron/blockscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (bs *TronBlockScanner) extractTxInput(tx *Contract, txExtractData *openwall

//主网from交易转账信息,第一个TxInput
txInput := &openwallet.TxInput{}
txInput.Recharge.Sid = openwallet.GenTxInputSID(tx.TxID, bs.wm.Symbol(), "", uint64(0))
txInput.Recharge.Sid = openwallet.GenTxInputSID(tx.TxID, bs.wm.Symbol(), coin.ContractID, uint64(0))
txInput.Recharge.TxID = tx.TxID
txInput.Recharge.Address = tx.From
txInput.Recharge.Coin = coin
Expand Down Expand Up @@ -543,7 +543,7 @@ func (bs *TronBlockScanner) extractTxOutput(tx *Contract, txExtractData *openwal

//主网to交易转账信息,只有一个TxOutPut
txOutput := &openwallet.TxOutPut{}
txOutput.Recharge.Sid = openwallet.GenTxOutPutSID(tx.TxID, bs.wm.Symbol(), "", uint64(0))
txOutput.Recharge.Sid = openwallet.GenTxOutPutSID(tx.TxID, bs.wm.Symbol(), coin.ContractID, uint64(0))
txOutput.Recharge.TxID = tx.TxID
txOutput.Recharge.Address = tx.To
txOutput.Recharge.Coin = coin
Expand Down
2 changes: 1 addition & 1 deletion tron/blockscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestTron_GetGlobalMaxBlockHeight(t *testing.T) {

func TestTron_GetTransaction(t *testing.T) {
bs := NewTronBlockScanner(tw)
txID := "2ebf6386991b079f6d301512385168c8e3216977e31560c343df9edc0f850534"
txID := "d414c54f51792e9383e9b9a19b67f0f34e8a3eccf3059757b8ea9a1b5a7de86c"
height := uint64(7773685)
tx, err := bs.wm.GetTransaction(txID, "", height, 0)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions tron/tx_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,15 @@ func (decoder *TransactionDecoder) CreateSimpleSummaryRawTransaction(wrapper ope
func (decoder *TransactionDecoder) CreateTokenSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error) {

var (
rawTxArray = make([]*openwallet.RawTransactionWithError, 0)
accountID = sumRawTx.Account.AccountID
minTransfer = common.StringNumToBigIntWithExp(sumRawTx.MinTransfer, Decimals)
retainedBalance = common.StringNumToBigIntWithExp(sumRawTx.RetainedBalance, Decimals)
rawTxArray = make([]*openwallet.RawTransactionWithError, 0)
accountID = sumRawTx.Account.AccountID
feesSupportAccount *openwallet.AssetsAccount
)

tokenDecimals := int32(sumRawTx.Coin.Contract.Decimals)
minTransfer := common.StringNumToBigIntWithExp(sumRawTx.MinTransfer, tokenDecimals)
retainedBalance := common.StringNumToBigIntWithExp(sumRawTx.RetainedBalance, tokenDecimals)

// 如果有提供手续费账户,检查账户是否存在
if feesAcount := sumRawTx.FeesSupportAccount; feesAcount != nil {
account, supportErr := wrapper.GetAssetsAccountInfo(feesAcount.AccountID)
Expand All @@ -608,7 +610,6 @@ func (decoder *TransactionDecoder) CreateTokenSummaryRawTransaction(wrapper open
feesSupportAccount = account
}

tokenDecimals := int32(sumRawTx.Coin.Contract.Decimals)
tokenProtocol := sumRawTx.Coin.Contract.Protocol

if minTransfer.Cmp(retainedBalance) < 0 {
Expand Down

0 comments on commit 20e0246

Please sign in to comment.