Skip to content

Commit b4e73a7

Browse files
committed
Fix darwinia-bridge provider tests error
1 parent 720e21c commit b4e73a7

File tree

8 files changed

+34
-10
lines changed

8 files changed

+34
-10
lines changed

utils/constant/chain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
ChainNameKeyInCtx ContextKey = "chain_name"
4040
LogKeyInCtx ContextKey = "log"
4141
NoticeFieldsKeyInCtx ContextKey = "notice_fields"
42+
FeeTestKeyInCtx ContextKey = "fee_test"
4243
)
4344

4445
var (

utils/provider/bridge/darwinia/crab2darwinia.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func Crab2Darwinia(ctx context.Context, args SwapParams) (tx *types.LegacyTx, er
9595
if err != nil {
9696
return nil, errors.Wrap(err, "fetchMsglineFeeAndParams")
9797
}
98+
if ctx.Value(constant.FeeTestKeyInCtx) != nil { // for test
99+
fee = ctx.Value(constant.FeeTestKeyInCtx).(decimal.Decimal)
100+
}
98101
if isNativeToken {
99102
data, err = WTokenLockAndXIssue(conf.targetChainId,
100103
wallet.GetAddress(true), wallet.GetAddress(true), args.Amount, args.Nonce, "", common.Bytes2Hex(param))

utils/provider/bridge/darwinia/crab2darwinia_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package darwinia
22

33
import (
4-
"github.com/ethereum/go-ethereum/common"
5-
"github.com/shopspring/decimal"
6-
"github.com/stretchr/testify/assert"
4+
"context"
75
"omni-balance/utils"
86
"omni-balance/utils/chains"
7+
"omni-balance/utils/constant"
98
"testing"
9+
10+
"github.com/ethereum/go-ethereum/common"
11+
"github.com/shopspring/decimal"
12+
"github.com/stretchr/testify/assert"
1013
)
1114

1215
func TestCrab2Darwinia(t *testing.T) {
1316
var (
1417
args = InitVar(t)
1518
amount = decimal.NewFromBigInt(chains.EthToWei(decimal.RequireFromString("0")), 0)
1619
)
20+
args.ctx = context.WithValue(args.ctx, constant.FeeTestKeyInCtx, decimal.RequireFromString("1"))
1721
tx, err := Crab2Darwinia(args.ctx, SwapParams{
1822
Sender: args.sender,
1923
TokenName: "CRAB",

utils/provider/bridge/darwinia/darwinia2crab.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func Darwinia2Crab(ctx context.Context, args SwapParams) (tx *types.LegacyTx, er
8989
if err != nil {
9090
return nil, errors.Wrap(err, "fetchMsglineFeeAndParams")
9191
}
92+
if ctx.Value(constant.FeeTestKeyInCtx) != nil { // for test
93+
fee = ctx.Value(constant.FeeTestKeyInCtx).(decimal.Decimal)
94+
}
9295
if isNativeToken {
9396
data, err = WTokenLockAndXIssue(tokenConf.targetChainId, realWallet, realWallet, args.Amount,
9497
args.Nonce, "", common.Bytes2Hex(param))

utils/provider/bridge/darwinia/darwinia2ethereum.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func Darwinia2ethereum(ctx context.Context, args SwapParams) (tx *types.LegacyTx
8282
return nil, errors.Wrap(err, "fetchMsglineFeeAndParams")
8383
}
8484

85+
if ctx.Value(constant.FeeTestKeyInCtx) != nil { // for test
86+
fee = ctx.Value(constant.FeeTestKeyInCtx).(decimal.Decimal)
87+
}
88+
8589
if isNativeToken {
8690
data, err = WTokenLockAndXIssue(tokenConf.targetChainId, tokenConf.recipient, realWallet,
8791
args.Amount, args.Nonce, common.Bytes2Hex(extData), common.Bytes2Hex(param))
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package darwinia
22

33
import (
4-
"github.com/ethereum/go-ethereum/common"
5-
"github.com/shopspring/decimal"
6-
"github.com/stretchr/testify/assert"
4+
"context"
75
"omni-balance/utils"
86
"omni-balance/utils/chains"
7+
"omni-balance/utils/constant"
98
"testing"
9+
10+
"github.com/ethereum/go-ethereum/common"
11+
"github.com/shopspring/decimal"
12+
"github.com/stretchr/testify/assert"
1013
)
1114

1215
func TestDarwinia2ethereum(t *testing.T) {
1316
var (
1417
args = InitVar(t)
1518
amount = decimal.NewFromBigInt(chains.EthToWei(decimal.RequireFromString("0")), 0)
1619
)
20+
args.ctx = context.WithValue(args.ctx, constant.FeeTestKeyInCtx, decimal.RequireFromString("1"))
1721
tx, err := Darwinia2ethereum(args.ctx, SwapParams{
1822
Sender: args.sender,
1923
TokenName: "RING",
@@ -22,7 +26,7 @@ func TestDarwinia2ethereum(t *testing.T) {
2226
Client: args.client,
2327
})
2428
assert.NoError(t, err)
25-
utils.AssertEqualFold(t, common.Bytes2Hex(tx.Data), "7104AAD500000000000000000000000000000000000000000000000000000000000000010000000000000000000000004CA75992D2750BEC270731A72DFDEDE6B9E71CC700000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018FC32B2D7900000000000000000000000000000000000000000000000000000000000000E000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000080000000000000000000000000C29DCB1F12A1618262EF9FBA673B77140ADC02D60000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001443EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000016FE400000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000")
29+
utils.AssertEqualFold(t, common.Bytes2Hex(tx.Data), "7104AAD500000000000000000000000000000000000000000000000000000000000000010000000000000000000000004CA75992D2750BEC270731A72DFDEDE6B9E71CC700000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018FC32B2D7900000000000000000000000000000000000000000000000000000000000000E000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000080000000000000000000000000C29DCB1F12A1618262EF9FBA673B77140ADC02D60000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001443EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000014CDE00000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000")
2630
assert.Equal(t, tx.To.Hex(), "0x092e19C46C9daAb7824393f1CD9c22f5BEA13560")
2731

2832
tx, err = Darwinia2ethereum(args.ctx, SwapParams{
@@ -33,6 +37,6 @@ func TestDarwinia2ethereum(t *testing.T) {
3337
Client: args.client,
3438
})
3539
assert.NoError(t, err)
36-
utils.AssertEqualFold(t, common.Bytes2Hex(tx.Data), "ac66b6a2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000004020000000000000000000000004ca75992d2750bec270731a72dfdede6b9e71cc700000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018fc32ddb4f00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000006000000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000016c0400000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000")
40+
utils.AssertEqualFold(t, common.Bytes2Hex(tx.Data), "AC66B6A2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000004020000000000000000000000004CA75992D2750BEC270731A72DFDEDE6B9E71CC700000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018FC32DDB4F00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000006000000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000148FD00000000000000000000000043EF13E84D9992D1461A1F90CAC4653658CEA4FD00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000")
3741
assert.Equal(t, tx.To.Hex(), "0x2B496f19A420C02490dB859fefeCCD71eDc2c046")
3842
}

utils/provider/bridge/darwinia/ethereum2darwinia.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func Ethereum2darwinia(ctx context.Context, args SwapParams) (tx *types.LegacyTx
8989
if err != nil {
9090
return nil, errors.Wrap(err, "FetchMsglineFeeAndParams")
9191
}
92+
if ctx.Value(constant.FeeTestKeyInCtx) != nil { // for test
93+
fee = ctx.Value(constant.FeeTestKeyInCtx).(decimal.Decimal)
94+
}
9295

9396
if strings.EqualFold(tokenConf.contractAddress.Hex(), constant.ZeroAddress.Hex()) {
9497
contractAddress = tokenConf.remoteAppAddress

utils/provider/bridge/darwinia/ethereum2darwinia_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestEthereum2darwinia(t *testing.T) {
3737
conf = InitVar(t)
3838
amount = decimal.NewFromBigInt(chains.EthToWei(decimal.RequireFromString("0")), 0)
3939
)
40+
conf.ctx = context.WithValue(conf.ctx, constant.FeeTestKeyInCtx, decimal.RequireFromString("1"))
4041

4142
type args struct {
4243
ctx context.Context
@@ -61,7 +62,8 @@ func TestEthereum2darwinia(t *testing.T) {
6162
Client: conf.client,
6263
},
6364
},
64-
wantData: "cf5a8bd80000000000000000000000004ca75992d2750bec270731a72dfdede6b9e71cc700000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018fc30e1b2100000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000080000000000000000000000000092e19c46c9daab7824393f1cd9c22f5bea135600000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001443ef13e84d9992d1461a1f90cac4653658cea4fd000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000579cc00000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
65+
66+
wantData: "cf5a8bd80000000000000000000000004ca75992d2750bec270731a72dfdede6b9e71cc700000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018fc30e1b2100000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000080000000000000000000000000092e19c46c9daab7824393f1cd9c22f5bea135600000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001443ef13e84d9992d1461a1f90cac4653658cea4fd000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000546f800000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
6567
wantTo: "0xc29dCb1F12a1618262eF9FBA673b77140adc02D6",
6668
wantErr: nil,
6769
},
@@ -77,7 +79,7 @@ func TestEthereum2darwinia(t *testing.T) {
7779
Client: conf.client,
7880
},
7981
},
80-
wantData: "57bf09850000000000000000000000009f284e1337a815fe77d2ff4ae46544645b20c5ff0000000000000000000000004ca75992d2750bec270731a72dfdede6b9e71cc700000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018fc31aa7e200000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000006000000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000051fcc00000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
82+
wantData: "57bf09850000000000000000000000009f284e1337a815fe77d2ff4ae46544645b20c5ff0000000000000000000000004ca75992d2750bec270731a72dfdede6b9e71cc700000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018fc31aa7e200000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000006000000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000545a200000000000000000000000043ef13e84d9992d1461a1f90cac4653658cea4fd00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
8183
wantTo: "0xDc0C760c0fB4672D06088515F6446a71Df0c64C1",
8284
wantErr: nil,
8385
},

0 commit comments

Comments
 (0)