Skip to content

Commit

Permalink
test: add Optimism, Arbitrum, Kcc test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
iosguang committed Jun 2, 2022
1 parent 7575f7b commit 5f369d1
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 39 deletions.
57 changes: 55 additions & 2 deletions core/eth/chain_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package eth

import (
"math/big"
"reflect"
"testing"

"github.com/coming-chat/wallet-SDK/core/base"
)

func TestChain_BalanceOfAddress(t *testing.T) {
addressBlackHole := "0x0000000000000000000000000000000000000000"
tests := []struct {
name string
net rpcInfo
Expand All @@ -22,7 +24,7 @@ func TestChain_BalanceOfAddress(t *testing.T) {
{
name: "eth black hole",
net: rpcs.ethereumProd,
address: "0x0000000000000000000000000000000000000000",
address: addressBlackHole,
},
{
name: "binance-prod normal",
Expand All @@ -45,6 +47,26 @@ func TestChain_BalanceOfAddress(t *testing.T) {
address: "0x62c3aF16954fba6D920835ec56f",
wantErr: true,
},
{
name: "optmism prod",
net: rpcs.optimismProd,
address: addressBlackHole,
},
{
name: "optimism test",
net: rpcs.optimismTest,
address: addressBlackHole,
},
{
name: "arbitrum prod",
net: rpcs.arbitrumProd,
address: addressBlackHole,
},
{
name: "kcc prod",
net: rpcs.kccProd,
address: addressBlackHole,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -55,7 +77,9 @@ func TestChain_BalanceOfAddress(t *testing.T) {
}
return
}
t.Log("queryed balance is ", got.Total)
totalFloat, _ := big.NewFloat(0).SetString(got.Total)
totalFloat.Quo(totalFloat, big.NewFloat(1000000000000000000))
t.Logf("BalanceOfAddress() balance ≈ %v, full = %v", totalFloat.String(), got.Total)
t.Log("Unable to verify balance, maybe you should check with this address which may be useful: " + tt.net.scan + "/address/" + tt.address)
})
}
Expand Down Expand Up @@ -85,6 +109,20 @@ func TestChain_FetchTransactionDetail(t *testing.T) {
FinishTimestamp: 1647598998,
},
},
{
name: "optimism prod erc20 token failured execution reverted",
args: args{rpcs.optimismProd, "0x13dfd70e710e8451cf88cf8bd55b02a525a45efe028309a019defe5ffc9d5e83"},
want: &base.TransactionDetail{
HashString: "0x13dfd70e710e8451cf88cf8bd55b02a525a45efe028309a019defe5ffc9d5e83",
Amount: "38919826",
EstimateFees: "36096000000",
FromAddress: "0x8F1c69De5E086BA1E441707B9cbD94860529beE4",
ToAddress: "0xE56BD3FfC787942F8aB9cf20D2D650E3184aCCc3",
Status: base.TransactionStatusFailure,
FinishTimestamp: 1654140210,
FailureMessage: "execution reverted",
},
},
{
name: "binance-test BNB failured out of gas",
args: args{rpcs.binanceTest, "0x5841f924fd76434f7f17ef8faf192142dbb5a363b9295eda0cc9f385e22399c7"},
Expand Down Expand Up @@ -171,6 +209,21 @@ func TestChain_FetchTransactionDetail_Cover_Multi_Rpcs(t *testing.T) {
args: args{rpcs.binanceProd, "0x5841f924fd76434f7f17ef8faf19214"},
wantErr: true,
},
{
name: "optimism prod succeed",
args: args{rpcs.optimismProd, "0xda38aaaaa858fb65f62a41455308e71a57cc6c5a1c647d7f80ba316362a5a31c"},
wantTime: 1654133507,
},
{
name: "arbitrum prod erc20 succeed",
args: args{rpcs.arbitrumProd, "0xc9b7e00273af851237f4cd76570da81942aca9b163044c6b7b9d09a46e17338b"},
wantTime: 1653897408,
},
{
name: "kcc prod succeed",
args: args{rpcs.kccProd, "0xb118c7957aacf4c63c8b723776ade76fd77d5411ea799741ce9edf80d6a5739f"},
wantTime: 1654119340,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
57 changes: 37 additions & 20 deletions core/eth/erc20token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func TestErc20Token_TokenInfo(t1 *testing.T) {
contract: rpcs.sherpaxTest.contracts.BUSD, // not a eth contract address
wantErr: true,
},
{
name: "optimism prod",
rpc: rpcs.optimismProd.url,
contract: "0x2e3d870790dc77a83dd1d18184acc7439a53f475",
want: &base.TokenInfo{Name: "Frax", Symbol: "FRAX", Decimal: 18},
},
}
for _, tt := range tests {
t1.Run(tt.name, func(t1 *testing.T) {
Expand Down Expand Up @@ -134,6 +140,12 @@ func TestErc20Token_BalanceOfAddress(t1 *testing.T) {
address: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
wantErr: true,
},
{
name: "optimism prod",
rpcInfo: rpcs.optimismProd,
contract: "0x2e3d870790dc77a83dd1d18184acc7439a53f475", // FRAX
address: "0xbba2379f5cc9a2f248c5cf18ad72379ae2478f42",
},
}
for _, tt := range tests {
t1.Run(tt.name, func(t1 *testing.T) {
Expand All @@ -154,41 +166,33 @@ func TestErc20Token_BalanceOfAddress(t1 *testing.T) {
}

func TestErc20Token_EstimateGasLimit(t1 *testing.T) {
enoughGasPrice := "100000000000" // 100 Gwei
haveEthUsdtAddress := "0x22fFF189C37302C02635322911c3B64f80CE7203"

tests := []struct {
name string
rpcInfo rpcInfo
contract string
from string
to string
amount string
wantErr bool
}{

{
name: "eth USDT",
rpcInfo: rpcs.ethereumProd,
contract: rpcs.ethereumProd.contracts.USDT,
from: haveEthUsdtAddress,
to: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
amount: "100",
},
{
name: "binance test USDC",
rpcInfo: rpcs.binanceTest,
contract: rpcs.binanceTest.contracts.BUSD,
from: "0x7Da8a0276627fa857f5459f4B1A9D8161226d604",
to: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
from: "0x22fFF189C37302C02635322911c3B64f80CE7203",
amount: "100",
},
// {
// name: "binance test USDC",
// rpcInfo: rpcs.binanceTest,
// contract: rpcs.binanceTest.contracts.BUSD,
// from: "0x7Da8a0276627fa857f5459f4B1A9D8161226d604",
// amount: "100",
// },
{
name: "sherpax prod USB",
rpcInfo: rpcs.sherpaxProd,
contract: rpcs.sherpaxProd.contracts.USB,
from: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
to: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
amount: "100",
wantErr: true, // ther is no balance.
},
Expand All @@ -197,7 +201,6 @@ func TestErc20Token_EstimateGasLimit(t1 *testing.T) {
rpcInfo: rpcInfo{url: rpcs.ethereumProd.url + "s"},
contract: rpcs.ethereumProd.contracts.USDT,
from: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
to: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
amount: "100",
wantErr: true,
},
Expand All @@ -206,22 +209,36 @@ func TestErc20Token_EstimateGasLimit(t1 *testing.T) {
rpcInfo: rpcs.sherpaxProd,
contract: rpcs.ethereumProd.contracts.USDT,
from: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
to: "0x7161ada3EA6e53E5652A45988DdfF1cE595E09c2",
amount: "100",
wantErr: true,
},
{
name: "optmism prod contract",
rpcInfo: rpcs.optimismProd,
contract: "0x2e3d870790dc77a83dd1d18184acc7439a53f475",
from: "0xbba2379f5cc9a2f248c5cf18ad72379ae2478f42",
amount: "1000000",
},
}
for _, tt := range tests {
t1.Run(tt.name, func(t1 *testing.T) {
chain := NewChainWithRpc(tt.rpcInfo.url)
gasPrice, err := chain.SuggestGasPrice()
if err != nil {
if !tt.wantErr {
t1.Errorf("EstimateGasLimit() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
tenfoldPrice := gasPrice.Value + "0"
token := chain.Erc20Token(tt.contract)
got, err := token.EstimateGasLimit(tt.from, tt.to, enoughGasPrice, tt.amount)
got, err := token.EstimateGasLimit(tt.from, accountCase1.address, tenfoldPrice, tt.amount)
if (err != nil) != tt.wantErr {
t1.Errorf("EstimateGasLimit() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil {
t1.Log(got)
t1.Logf("EstimateGasLimit() %v", got)
}
})
}
Expand Down
54 changes: 47 additions & 7 deletions core/eth/rpc_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type contracts struct {
type rpcInfo struct {
url string
scan string
contracts contracts
contracts *contracts
}
type rpcConfig struct {
ethereumProd rpcInfo
Expand All @@ -21,53 +21,93 @@ type rpcConfig struct {
binanceProd rpcInfo
sherpaxTest rpcInfo
sherpaxProd rpcInfo

optimismProd rpcInfo
optimismTest rpcInfo
arbitrumProd rpcInfo
arbitrumTest rpcInfo
kccProd rpcInfo
kccTest rpcInfo
}

var rpcs = rpcConfig{
ethereumProd: rpcInfo{
"https://geth-mainnet.coming.chat",
"https://etherscan.io",
contracts{
&contracts{
USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
}},
rinkeby: rpcInfo{
"https://rinkeby.infura.io/v3/161645ea57d2494d996c4d2de2489419",
"",
contracts{},
nil,
},
binanceTest: rpcInfo{
"https://data-seed-prebsc-1-s1.binance.org:8545",
"https://testnet.bscscan.com",
contracts{
&contracts{
USDT: "0x6cd2Bf22B3CeaDfF6B8C226487265d81164396C5",
BUSD: "0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee",
USDC: "0x0644014472cD39f51f57ce91be871537D7A5A2Ab",
}},
binanceProd: rpcInfo{
"https://bsc-dataseed.binance.org",
"https://bscscan.com",
contracts{
&contracts{
USDT: "0x55d398326f99059fF775485246999027B3197955",
BUSD: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
}},
sherpaxTest: rpcInfo{
"https://sherpax-testnet.chainx.org/rpc",
"https://evm-pre.sherpax.io",
contracts{
&contracts{
USDT: "0x1635583ACf7beF762E8119887b2f3B9F9BcD1742",
BUSD: "0x77eD6a802aB1d60A86F2e3c45B43a0Cd7Ee2572B",
USDC: "0xa017362eB5B22302e4E5c55786f651214BD168A2",
}},
sherpaxProd: rpcInfo{
"https://mainnet.sherpax.io/rpc",
"https://evm.sherpax.io",
contracts{
&contracts{
USB: "0xE7e312dfC08e060cda1AF38C234AEAcc7A982143",
USDT: "0x4B53739D798EF0BEa5607c254336b40a93c75b52",
BUSD: "0x37088186089c7D6BcD556d9A15087DFaE3Ba0C32",
USDC: "0x935CC842f220CF3A7D10DA1c99F01B1A6894F7C5",
}},

optimismProd: rpcInfo{
"https://mainnet.optimism.io",
"https://optimistic.etherscan.io",
nil,
},
optimismTest: rpcInfo{
"https://kovan.optimism.io",
"https://kovan-optimistic.etherscan.io",
nil,
},

arbitrumProd: rpcInfo{
"https://arb1.arbitrum.io/rpc",
"https://arbiscan.io",
nil,
},
arbitrumTest: rpcInfo{
"https://rinkeby.arbitrum.io/rpc",
"https://testnet.arbiscan.io",
nil,
},

kccProd: rpcInfo{
"https://rpc-mainnet.kcc.network",
"https://scan.kcc.io",
nil,
},
kccTest: rpcInfo{
"https://rpc-testnet.kcc.network",
"https://scan-testnet.kcc.network",
nil,
},
}

func (n *rpcInfo) Chain() *Chain {
Expand Down
Loading

0 comments on commit 5f369d1

Please sign in to comment.