Skip to content

Commit f2412ef

Browse files
committed
update tests
1 parent 9e47e65 commit f2412ef

File tree

2 files changed

+233
-26
lines changed

2 files changed

+233
-26
lines changed

openwsdk/api_node_test.go

Lines changed: 187 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func init() {
2222

2323
func testNewAPINode() *APINode {
2424

25-
//confFile := filepath.Join("conf", "node.ini")
26-
confFile := filepath.Join("conf", "test.ini")
25+
confFile := filepath.Join("conf", "node.ini")
26+
//confFile := filepath.Join("conf", "test.ini")
2727
c, err := config.NewConfig("ini", confFile)
2828
if err != nil {
2929
log.Error("NewConfig error:", err)
@@ -176,7 +176,7 @@ func TestAPINode_CreateAccount(t *testing.T) {
176176
}
177177

178178
symbol := &Symbol{}
179-
symbol.Coin = "QUORUM"
179+
symbol.Coin = "ETP"
180180
symbol.Curve = int64(owcrypt.ECC_CURVE_SECP256K1)
181181

182182
var findWallet *Wallet
@@ -219,7 +219,7 @@ func TestAPINode_CreateAccount(t *testing.T) {
219219
}
220220

221221
func TestAPINode_FindAccountByWalletID(t *testing.T) {
222-
walletID := "W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx"
222+
walletID := ""
223223
api := testNewAPINode()
224224
api.FindAccountByWalletID(walletID, true,
225225
func(status uint64, msg string, accounts []*Account) {
@@ -295,7 +295,7 @@ func TestAPINode_CreateBatchAddress(t *testing.T) {
295295
}
296296

297297
func TestAPINode_FindAddressByAddress(t *testing.T) {
298-
addr := "1QGPMCCtXaop8C2J2mUf3DcofjYgiD8prd"
298+
addr := "0xc21a2eb0eea50060efb9307627c6d0046ca57d8d"
299299
api := testNewAPINode()
300300
api.FindAddressByAddress(addr, true,
301301
func(status uint64, msg string, address *Address) {
@@ -308,16 +308,16 @@ func TestAPINode_FindAddressByAddress(t *testing.T) {
308308
}
309309

310310
func TestAPINode_FindAddressByAccountID(t *testing.T) {
311-
accountID := "Ey6MU7v5CdPbpy9Ph18d2v4HwgNAG6UDgQEFfKCRmUZE"
311+
accountID := "5qEpgFJFdbUQnQccXKyZoE8YBYoKSoHCgPCPVcy9mhVL"
312312
api := testNewAPINode()
313-
api.FindAddressByAccountID(accountID, 0, 10, true,
313+
api.FindAddressByAccountID(accountID, 7200, 50, true,
314314
func(status uint64, msg string, addresses []*Address) {
315315

316316
if status != owtp.StatusSuccess {
317317
return
318318
}
319-
for i, a := range addresses {
320-
log.Infof("Address[%d]:%+v", i, a)
319+
for _, a := range addresses {
320+
log.Infof("Address: %s, Index: %d", a.Address, a.AddrIndex)
321321
}
322322
})
323323
}
@@ -350,6 +350,33 @@ func testCreateTrade(
350350
return retRawTx, err
351351
}
352352

353+
func testCreateBatchTrade(
354+
accountID string,
355+
sid string,
356+
coin Coin,
357+
to map[string]string,
358+
feeRate string,
359+
) (*RawTransaction, error) {
360+
361+
var (
362+
retRawTx *RawTransaction
363+
err error
364+
)
365+
366+
api := testNewAPINode()
367+
api.CreateBatchTrade(accountID, sid, coin, to, feeRate, "", "", true,
368+
func(status uint64, msg string, rawTx *RawTransaction) {
369+
if status != owtp.StatusSuccess {
370+
err = fmt.Errorf(msg)
371+
return
372+
}
373+
374+
retRawTx = rawTx
375+
})
376+
377+
return retRawTx, err
378+
}
379+
353380
func testSubmitTrade(
354381
rawTx []*RawTransaction,
355382
) ([]*Transaction, []*FailedRawTransaction, error) {
@@ -631,6 +658,29 @@ func TestAPINode_GetAllTokenBalanceByAddress(t *testing.T) {
631658
})
632659
}
633660

661+
func TestAPINode_GetAllTokenBalanceOfAddressByAccountID(t *testing.T) {
662+
accountID := "HDGv4GwxfRcGWZBn8Xfp3bJ4zJTTGrajWbjQrRTvMDsG"
663+
api := testNewAPINode()
664+
getAddrs := make([]*Address, 0)
665+
api.FindAddressByAccountID(accountID, 800, 200, true,
666+
func(status uint64, msg string, addresses []*Address) {
667+
668+
if status != owtp.StatusSuccess {
669+
return
670+
}
671+
getAddrs = addresses
672+
})
673+
for _, a := range getAddrs {
674+
api.GetAllTokenBalanceByAddress(accountID, a.Address, "XWC", true,
675+
func(status uint64, msg string, balance []*TokenBalance) {
676+
for _, b := range balance {
677+
log.Infof("address: %s, index: %d, token: %s, balance: %s", a.Address, a.AddrIndex, b.Token, b.Balance.Balance)
678+
}
679+
})
680+
}
681+
682+
}
683+
634684
func TestAPINode_ImportAccount(t *testing.T) {
635685
account := &Account{
636686
WalletID: "WLN3hJo3NcsbWpsbBjezbJWoy7unZfcaGT",
@@ -730,18 +780,19 @@ func TestAPINode_FindWalletByParams(t *testing.T) {
730780
func TestAPINode_FindAddressByParams(t *testing.T) {
731781
api := testNewAPINode()
732782
param := map[string]interface{}{
733-
"walletIDs": []string{"W3LxqTNAcXFqW7HGcTuERRLXKdNWu17Ccx"},
734-
"symbol": "QUORUM",
783+
"walletIDs": []string{"WLVEGBFFSevB5tfsdgKPVGw9zFwccYtafn"},
784+
"accountIDs": []string{"5qEpgFJFdbUQnQccXKyZoE8YBYoKSoHCgPCPVcy9mhVL"},
785+
"symbol": "BSC",
735786
}
736-
api.FindAddressByParams(param, 0, 100, true,
787+
api.FindAddressByParams(param, 7250, 50, true,
737788
func(status uint64, msg string, addresses []*Address) {
738789
if status != owtp.StatusSuccess {
739790
t.Errorf(msg)
740791
return
741792
}
742-
793+
log.Infof("total addresses: %d", len(addresses))
743794
for _, a := range addresses {
744-
log.Infof("address: %+v", a)
795+
log.Infof("address: %s, index: %d", a.Address, a.AddrIndex)
745796
}
746797
})
747798
}
@@ -755,13 +806,22 @@ func TestAPINode_CreateSummaryTx(t *testing.T) {
755806
)
756807

757808
api := testNewAPINode()
758-
accountID := ""
759-
sumAddress := ""
809+
accountID := "HDGv4GwxfRcGWZBn8Xfp3bJ4zJTTGrajWbjQrRTvMDsG"
810+
sumAddress := "XWCNjAfoTwK77dJw58VthU5YKKG9kUfLHvcbK"
760811
coin := Coin{
761-
Symbol: "",
762-
IsContract: false,
812+
Symbol: "XWC",
813+
IsContract: true,
814+
ContractID: "BJftiCFBOsJ3Vu54QfSHXnqwhDbTzQDzF+e62mUsBe8=",
815+
ContractAddress: "1.3.0",
763816
}
764817

818+
//feeSupport := &FeesSupportAccount{
819+
// AccountID: "7dSaDccksuj75DEhtw3LwSCQbybRfVPhxPv8DGDD4M9o",
820+
// LowBalanceWarning: "0.001",
821+
// LowBalanceStop: "0.0001",
822+
// FeesScale: "2",
823+
//}
824+
765825
api.FindAccountByAccountID(accountID, 0, true,
766826
func(status uint64, msg string, account *Account) {
767827
if status != owtp.StatusSuccess {
@@ -775,7 +835,10 @@ func TestAPINode_CreateSummaryTx(t *testing.T) {
775835
t.Errorf("error: %v", retErr)
776836
return
777837
}
778-
838+
if retAccountInfo == nil {
839+
t.Errorf("retAccountInfo is nil")
840+
return
841+
}
779842
log.Infof("total address = %d", retAccountInfo.AddressIndex+1)
780843

781844
for i := 0; i <= int(retAccountInfo.AddressIndex); i = i + addressLimit {
@@ -784,12 +847,24 @@ func TestAPINode_CreateSummaryTx(t *testing.T) {
784847
log.Infof("sid = %s", sid)
785848
api.CreateSummaryTx(accountID, sumAddress, coin,
786849
"", "0", "0",
787-
i, addressLimit, 0,
850+
i, addressLimit, 1,
788851
sid, nil, "", true,
789852
func(status uint64, msg string, rawTxs []*RawTransaction) {
853+
if status != owtp.StatusSuccess {
854+
log.Errorf(msg)
855+
return
856+
}
790857
for _, tx := range rawTxs {
791-
log.Infof("from: %+v", tx.Signatures[accountID][0].Address)
792-
//log.Infof("tx: %+v", tx)
858+
//log.Infof("from: %+v", tx.Signatures[accountID][0].Address)
859+
log.Infof("tx: %+v", tx)
860+
for _, sigs := range tx.Signatures {
861+
for _, sig := range sigs {
862+
log.Infof("address: %s, nonce: %s", sig.Address, sig.Nonce)
863+
}
864+
}
865+
if tx.ErrorMsg != nil && tx.ErrorMsg.Code != 0 {
866+
log.Warning(tx.ErrorMsg.Err)
867+
}
793868
}
794869
})
795870
}
@@ -813,13 +888,13 @@ func TestAPINode_VerifyAddress(t *testing.T) {
813888

814889
func TestAPINode_CallSmartContractABI(t *testing.T) {
815890
api := testNewAPINode()
816-
accountID := "5kTzFGuAH9UkB9yhZdmXtF8hGPh6iPt4hf8Q3DVy3Xo3"
891+
accountID := "AVrCpwbnGRHEk2HCHTGJ3abFkMARLzarCLCaDpH56H3H"
817892
coin := Coin{
818-
Symbol: "QUORUM",
893+
Symbol: "TDEX",
819894
IsContract: true,
820-
ContractID: "dl8WD7bM7xk4ZxRybuHCo3JDDtZn2ugPusapoKnQEWA=",
895+
ContractID: "VVLWoJe++pOGMU8oxp174T+66n3BrP7vG6Mcyqogtqk=",
821896
}
822-
abiParam := []string{"balanceOf", "0xe6a9cc4fe66e7b726e3e8ef8e32c308ce74c0996"}
897+
abiParam := []string{"balanceOf", "0x941f298dc3ec1728e21065e84237159958a5b20a"}
823898
api.CallSmartContractABI(accountID, coin, abiParam, "", 0,
824899
true, func(status uint64, msg string, callResult *SmartContractCallResult) {
825900
if status != owtp.StatusSuccess {
@@ -1027,3 +1102,89 @@ func TestAPINode_CreateSmartContractTradeMulti(t *testing.T) {
10271102
wait.Wait()
10281103

10291104
}
1105+
1106+
func TestAPINode_CreateBatchTrade(t *testing.T) {
1107+
accountID := "BtbecAGzVMFX4PT1QjKpQ1cDKhWtJcFqPoLP5CVi2gVt"
1108+
sid := uuid.New().String()
1109+
feeRate := ""
1110+
1111+
coin := Coin{
1112+
Symbol: "ETP",
1113+
IsContract: true,
1114+
ContractID: "q7OtI9+EP6Ze8LNvJDGStyS15mzhnntduQ3wcphv9Zc=",
1115+
}
1116+
1117+
receivers := map[string]string{
1118+
"M8zhymCjZD9ZzSR9skirEhJnNDEdcJBb6c": "1",
1119+
"MC3byQPhQS9dQYkY4ME5R94j5GksWvDYTR": "1",
1120+
"MDgW56oXUFMRfSuRhPcyoWcGwSyj81hUnM": "1",
1121+
"MHr2w1nQ2aiGuh7McpAvi5TMvqmzVLJeNC": "1",
1122+
"MMRbpJdtxXeNmdwRZa4JjNgraL2XKUeg4e": "1",
1123+
"MNVJdDfesiRdPMWz1QCnyvAXTbTcfdaBun": "1",
1124+
}
1125+
1126+
rawTx, err := testCreateBatchTrade(accountID, sid, coin, receivers, feeRate)
1127+
if err != nil {
1128+
t.Logf("CreateTrade unexpected error: %v\n", err)
1129+
return
1130+
}
1131+
log.Infof("rawTx: %+v", rawTx)
1132+
1133+
key, err := testGetLocalKey()
1134+
if err != nil {
1135+
t.Logf("GetKey error: %v\n", err)
1136+
return
1137+
}
1138+
1139+
//签名交易单
1140+
err = SignRawTransaction(rawTx, key)
1141+
if err != nil {
1142+
t.Logf("SignRawTransaction unexpected error: %v\n", err)
1143+
return
1144+
}
1145+
1146+
log.Infof("signed rawTx: %+v", rawTx)
1147+
1148+
success, fail, err := testSubmitTrade([]*RawTransaction{rawTx})
1149+
if err != nil {
1150+
t.Logf("SubmitTrade unexpected error: %v\n", err)
1151+
return
1152+
}
1153+
1154+
log.Info("============== success ==============")
1155+
1156+
for _, tx := range success {
1157+
log.Infof("tx: %+v", tx)
1158+
}
1159+
1160+
log.Info("")
1161+
1162+
log.Info("============== fail ==============")
1163+
1164+
for _, tx := range fail {
1165+
log.Infof("tx: %+v", tx.Reason)
1166+
}
1167+
}
1168+
1169+
func TestAPINode_CreateTrade(t *testing.T) {
1170+
accountID := "B6UbwNZrz82QqUPBsSCPUkEJ1CjxSzSwnewziCseCt4c"
1171+
sid := uuid.New().String()
1172+
amount := "3266824611.6667"
1173+
address := "MQFXFvYmVmr7LTCPMs61wLiZvrgg2vnN75"
1174+
feeRate := ""
1175+
1176+
coin := Coin{
1177+
Symbol: "ETP",
1178+
IsContract: true,
1179+
ContractID: "q7OtI9+EP6Ze8LNvJDGStyS15mzhnntduQ3wcphv9Zc=",
1180+
ContractAddress: "DNA",
1181+
ContractABI: "",
1182+
}
1183+
1184+
rawTx, err := testCreateTrade(accountID, sid, coin, amount, address, feeRate)
1185+
if err != nil {
1186+
t.Logf("CreateTrade unexpected error: %v\n", err)
1187+
return
1188+
}
1189+
log.Infof("rawTx: %+v", rawTx)
1190+
}

openwsdk/api_transmit_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,49 @@ func TestTransmitNode_SignHashViaTrustNode(t *testing.T) {
548548
})
549549
})
550550
}
551+
552+
func TestServeTransmitNode(t *testing.T) {
553+
554+
testRunTimeTask := func (tn *TransmitNode) {
555+
for {
556+
//log.Debugf("call time task")
557+
nodeID := "2Thz4GfdwRqj4zmtfhqrzARWUP5FwFmzyFr68xaWKLXt"
558+
tn.UpdateInfoViaTrustNode(nodeID, true,
559+
func(status uint64, msg string) {
560+
log.Infof("status: %v, msg: %v", status, msg)
561+
})
562+
time.Sleep(5 * time.Second)
563+
}
564+
}
565+
566+
api := testNewAPINode()
567+
err := api.ServeTransmitNode("127.0.0.1:9088")
568+
if err != nil {
569+
log.Errorf("ServeTransmitNode error: %v\n", err)
570+
return
571+
}
572+
573+
tn, err := api.TransmitNode()
574+
if err != nil {
575+
log.Errorf("TransmitNode error: %v\n", err)
576+
return
577+
}
578+
579+
proxyNode, err := api.ServeProxyNode(":7088")
580+
if err != nil {
581+
log.Errorf("ServeProxyNode error: %v\n", err)
582+
return
583+
}
584+
585+
proxyNode.SetProxyRequestHandler(func(ctx *owtp.Context) bool {
586+
return true
587+
})
588+
589+
proxyNode.SetProxyResponseHandler(func(ctx *owtp.Context) bool {
590+
return true
591+
})
592+
593+
testRunTimeTask(tn)
594+
595+
}
596+

0 commit comments

Comments
 (0)