Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit b5b1cf4

Browse files
authored
Merge pull request #1857 from OpenBazaar/eth_qa_fix
Fix the eth qa tests
2 parents 296c3a6 + a4f9e6c commit b5b1cf4

15 files changed

+55
-55
lines changed

core/disputes.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"math/big"
99
"strconv"
10-
"strings"
1110
"sync"
1211
"time"
1312

@@ -28,6 +27,7 @@ import (
2827
"github.com/OpenBazaar/openbazaar-go/pb"
2928
"github.com/OpenBazaar/openbazaar-go/repo"
3029
"github.com/OpenBazaar/openbazaar-go/repo/db"
30+
"github.com/OpenBazaar/openbazaar-go/util"
3131
)
3232

3333
// DisputeWg - waitgroup for disputes
@@ -77,7 +77,7 @@ func (n *OpenBazaarNode) OpenDispute(orderID string, contract *pb.RicardianContr
7777
var outpoints []*pb.Outpoint
7878
for _, r := range records {
7979
o := new(pb.Outpoint)
80-
o.Hash = strings.TrimPrefix(r.Txid, "0x")
80+
o.Hash = util.NormalizeAddress(r.Txid)
8181
o.Index = r.Index
8282
o.BigValue = r.Value.String()
8383
outpoints = append(outpoints, o)
@@ -167,7 +167,7 @@ func (n *OpenBazaarNode) verifyEscrowFundsAreDisputeable(contract *pb.RicardianC
167167
return false
168168
}
169169
for _, r := range records {
170-
hash, err := chainhash.NewHashFromStr(strings.TrimPrefix(r.Txid, "0x"))
170+
hash, err := chainhash.NewHashFromStr(util.NormalizeAddress(r.Txid))
171171
if err != nil {
172172
log.Errorf("Failed NewHashFromStr(%s): %s", r.Txid, err.Error())
173173
return false
@@ -361,7 +361,7 @@ func (n *OpenBazaarNode) ProcessDisputeOpen(rc *pb.RicardianContract, peerID str
361361
var outpoints []*pb.Outpoint
362362
for _, r := range records {
363363
o := new(pb.Outpoint)
364-
o.Hash = strings.TrimPrefix(r.Txid, "0x")
364+
o.Hash = util.NormalizeAddress(r.Txid)
365365
o.Index = r.Index
366366
o.BigValue = r.Value.String()
367367
outpoints = append(outpoints, o)
@@ -421,7 +421,7 @@ func (n *OpenBazaarNode) ProcessDisputeOpen(rc *pb.RicardianContract, peerID str
421421
var outpoints []*pb.Outpoint
422422
for _, r := range records {
423423
o := new(pb.Outpoint)
424-
o.Hash = strings.TrimPrefix(r.Txid, "0x")
424+
o.Hash = util.NormalizeAddress(r.Txid)
425425
o.Index = r.Index
426426
o.BigValue = r.Value.String()
427427
outpoints = append(outpoints, o)
@@ -959,7 +959,7 @@ func (n *OpenBazaarNode) ValidateCaseContract(contract *pb.RicardianContract) []
959959
return validationErrors
960960
}
961961

962-
if strings.TrimPrefix(order.Payment.Address, "0x") != strings.TrimPrefix(addr.String(), "0x") {
962+
if util.NormalizeAddress(order.Payment.Address) != util.NormalizeAddress(addr.String()) {
963963
validationErrors = append(validationErrors, "The calculated bitcoin address doesn't match the address in the order")
964964
}
965965

@@ -1071,7 +1071,7 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
10711071
resolution = repo.ToV5DisputeResolution(contract.DisputeResolution)
10721072
)
10731073
for _, o := range resolution.Payout.Inputs {
1074-
decodedHash, err := hex.DecodeString(strings.TrimPrefix(o.Hash, "0x"))
1074+
decodedHash, err := hex.DecodeString(util.NormalizeAddress(o.Hash))
10751075
if err != nil {
10761076
return err
10771077
}
@@ -1211,7 +1211,7 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
12111211
}
12121212

12131213
err = n.SendOrderPayment(&SpendResponse{
1214-
Txid: strings.TrimPrefix(hexutil.Encode(txnID), "0x"),
1214+
Txid: util.NormalizeAddress(hexutil.Encode(txnID)),
12151215
Currency: &currencyDef,
12161216
OrderID: orderID,
12171217
PeerID: peerID,

net/service/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ func (service *OpenBazaarService) handleOrderCompletion(p peer.ID, pmes *pb.Mess
11871187
outValue := big.NewInt(0)
11881188
for _, r := range records {
11891189
if !r.Spent && r.Value.Cmp(big.NewInt(0)) > 0 {
1190-
outpointHash, err := hex.DecodeString(r.Txid)
1190+
outpointHash, err := hex.DecodeString(ut.NormalizeAddress(r.Txid))
11911191
if err != nil {
11921192
return nil, err
11931193
}

qa/eth_cancel_direct_offline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def run_test(self):
152152

153153
# startup alice again
154154
self.start_node(alice)
155-
time.sleep(45)
155+
time.sleep(160)
156156

157157
# check alice detected order
158158
api_url = alice["gateway_url"] + "ob/order/" + orderId

qa/eth_complete_moderated_online.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def run_test(self):
218218
if r.status_code != 200:
219219
raise TestFailure("EthCompleteModeratedOnlineTest - FAIL: Couldn't load order from Alice")
220220
resp = json.loads(r.text)
221+
print("############ $$$$$$$$$$$$$$")
222+
print(resp["state"])
221223
if resp["state"] != "COMPLETED":
222224
raise TestFailure("EthCompleteModeratedOnlineTest - FAIL: Alice failed to detect order completion")
223225

qa/eth_purchase_direct_online.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def run_test(self):
162162
raise TestFailure("EthPurchaseDirectOnlineTest - FAIL: Purchase POST failed with incorrect reason: %s", resp["reason"])
163163
if resp["code"] != "ERR_INSUFFICIENT_INVENTORY":
164164
raise TestFailure("EthPurchaseDirectOnlineTest - FAIL: Purchase POST failed with incorrect code: %s", resp["code"])
165-
if resp["remainingInventory"] != 6:
165+
if resp["remainingInventory"] != '6':
166166
raise TestFailure("EthPurchaseDirectOnlineTest - FAIL: Purchase POST failed with incorrect remainingInventory: %d", resp["remainingInventory"])
167167

168168
print("EthPurchaseDirectOnlineTest - PASS")

qa/eth_reject_moderated_offline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def run_test(self):
154154
if resp["state"] != "PENDING":
155155
raise TestFailure("EthRejectModeratedOffline - FAIL: Bob purchase saved in incorrect state")
156156

157-
157+
158158
# startup alice again
159159
self.start_node(alice)
160160
time.sleep(45)
@@ -171,7 +171,7 @@ def run_test(self):
171171
elif r.status_code != 200:
172172
resp = json.loads(r.text)
173173
raise TestFailure("EthRejectModeratedOffline - FAIL: OrderConfirmation POST failed. Reason: %s", resp["reason"])
174-
time.sleep(20)
174+
time.sleep(120)
175175

176176
# alice check order rejected correctly
177177
api_url = alice["gateway_url"] + "ob/order/" + orderId
@@ -195,7 +195,7 @@ def run_test(self):
195195
#if len(resp["paymentAddressTransactions"]) != 2:
196196
# raise TestFailure("EthRejectModeratedOffline - FAIL: Bob failed to detect outgoing payment")
197197

198-
198+
199199
time.sleep(2)
200200

201201
# Check the funds moved into bob's wallet

qa/manage_crypto_listings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def run_test(self):
4545
raise TestFailure("ManageCryptoListingsTest - FAIL: Incorrect listing count: %d", len(resp))
4646
for listing in resp:
4747
if listing['contractType'] == 'CRYPTOCURRENCY':
48-
if listing["cryptoCurrencyCode"] != "TETH":
48+
if listing["coinType"] != "TETH":
4949
raise TestFailure("ManageCryptoListingsTest - FAIL: cryptoCurrencyCode incorrect: %s", listing["cryptoCurrencyCode"])
5050

5151
# delete listing

qa/purchase_crypto_listing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run_test(self):
5555
resp = json.loads(r.text)
5656
if r.status_code != 200:
5757
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory get endpoint failed")
58-
if resp["ether"]["inventory"] != 350000000:
58+
if resp["ether"]["inventory"] != "350000000":
5959
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory incorrect: %d", resp["ether"]["inventory"])
6060

6161
# get listing hash
@@ -64,7 +64,7 @@ def run_test(self):
6464
if r.status_code != 200:
6565
raise TestFailure("PurchaseCryptoListingTest - FAIL: Couldn't get listing index")
6666
resp = json.loads(r.text)
67-
if resp[0]["coinType"] != "BCH":
67+
if resp[0]["coinType"] != "TETH":
6868
raise TestFailure("PurchaseCryptoListingTest - FAIL: Vendor incorrectly saved listings.json without a coinType")
6969
listingId = resp[0]["hash"]
7070

@@ -97,7 +97,7 @@ def run_test(self):
9797
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer purchase saved in incorrect state")
9898
if resp["funded"] == True:
9999
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer incorrectly saved as funded")
100-
if resp["contract"]["vendorListings"][0]["metadata"]["coinType"] != "BCH":
100+
if resp["contract"]["vendorListings"][0]["metadata"]["coinType"] != "TETH":
101101
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer incorrectly saved without a coinType")
102102
if resp["contract"]["buyerOrder"]["items"][0]["paymentAddress"] != "crypto_payment_address":
103103
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer incorrectly saved without a paymentAddress")
@@ -112,7 +112,7 @@ def run_test(self):
112112
raise TestFailure("PurchaseCryptoListingTest - FAIL: Vendor purchase saved in incorrect state")
113113
if resp["funded"] == True:
114114
raise TestFailure("PurchaseCryptoListingTest - FAIL: Vendor incorrectly saved as funded")
115-
if resp["contract"]["vendorListings"][0]["metadata"]["coinType"] != "BCH":
115+
if resp["contract"]["vendorListings"][0]["metadata"]["coinType"] != "TETH":
116116
raise TestFailure("PurchaseCryptoListingTest - FAIL: Vendor incorrectly saved without a coinType")
117117
if resp["contract"]["buyerOrder"]["items"][0]["paymentAddress"] != "crypto_payment_address":
118118
raise TestFailure("PurchaseCryptoListingTest - FAIL: Vendor incorrectly saved without a paymentAddress")
@@ -146,7 +146,7 @@ def run_test(self):
146146
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer failed to detect his payment")
147147
if resp["funded"] == False:
148148
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer incorrectly saved as unfunded")
149-
if resp["contract"]["vendorListings"][0]["metadata"]["coinType"] != "BCH":
149+
if resp["contract"]["vendorListings"][0]["metadata"]["coinType"] != "TETH":
150150
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer incorrectly saved without a coinType")
151151
if resp["contract"]["buyerOrder"]["items"][0]["paymentAddress"] != "crypto_payment_address":
152152
raise TestFailure("PurchaseCryptoListingTest - FAIL: Buyer incorrectly saved without a paymentAddress")
@@ -191,7 +191,7 @@ def run_test(self):
191191
resp = json.loads(r.text)
192192
if r.status_code != 200:
193193
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory get endpoint failed")
194-
if resp["ether"]["inventory"] != 250000000:
194+
if resp["ether"]["inventory"] != "250000000":
195195
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory incorrect: %d", resp["ether"]["inventory"])
196196

197197
print("PurchaseCryptoListingTest - PASS")

qa/purchase_direct_online.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def run_test(self):
152152
raise TestFailure("PurchaseDirectOnlineTest - FAIL: Purchase POST failed with incorrect reason: %s", resp["reason"])
153153
if resp["code"] != "ERR_INSUFFICIENT_INVENTORY":
154154
raise TestFailure("PurchaseDirectOnlineTest - FAIL: Purchase POST failed with incorrect code: %s", resp["code"])
155-
if resp["remainingInventory"] != 6:
155+
if resp["remainingInventory"] != "6":
156156
raise TestFailure("PurchaseDirectOnlineTest - FAIL: Purchase POST failed with incorrect remainingInventory: %d", resp["remainingInventory"])
157157

158158
print("PurchaseDirectOnlineTest - PASS")

qa/testdata/eth_digital.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
"contractType": "DIGITAL_GOOD",
66
"format": "FIXED_PRICE",
77
"expiry": "2030-08-17T04:52:19.000Z",
8-
"acceptedCurrencies": ["ETH"]
8+
"acceptedCurrencies": ["TETH"]
99
},
1010
"item": {
1111
"title": "Citizenfour",
1212
"description": "A documentarian and a reporter travel to Hong Kong for the first of many meetings with Edward Snowden.",
1313
"processingTime": "1 confirmation",
1414
"bigPrice": "12000000",
15-
"priceCurrency": {
16-
"code": "ETH",
17-
"divisibility": 18,
18-
"name": "Eth",
19-
"currencyType": "crypto"
20-
},
15+
"priceCurrency": {
16+
"code": "TETH",
17+
"divisibility": 18,
18+
"name": "Eth",
19+
"currencyType": "crypto"
20+
},
2121
"tags": [
2222
"documentary"
2323
],

0 commit comments

Comments
 (0)