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

Commit 39b1230

Browse files
committed
Fix bug creating v4 moderated order
1 parent bd6707c commit 39b1230

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

core/order.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,6 @@ func prepareModeratedOrderContract(data *repo.PurchaseData, n *OpenBazaarNode, c
217217
payment := new(pb.Order_Payment)
218218
payment.Method = pb.Order_Payment_MODERATED
219219
payment.Moderator = data.Moderator
220-
defn, err := n.LookupCurrency(data.PaymentCoin)
221-
if err != nil {
222-
return nil, errors.New("invalid payment coin")
223-
}
224-
payment.AmountCurrency = &pb.CurrencyDefinition{
225-
Code: defn.Code.String(),
226-
Divisibility: uint32(defn.Divisibility),
227-
}
228220

229221
profile, err := n.FetchProfile(data.Moderator, true)
230222
if err != nil {
@@ -242,11 +234,19 @@ func prepareModeratedOrderContract(data *repo.PurchaseData, n *OpenBazaarNode, c
242234
return nil, errors.New("moderator does not accept our currency")
243235
}
244236
contract.BuyerOrder.Payment = payment
237+
defn, err := n.LookupCurrency(data.PaymentCoin)
238+
if err != nil {
239+
return nil, errors.New("invalid payment coin")
240+
}
245241
if contract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
246242
payment.AmountCurrency = &pb.CurrencyDefinition{
247243
Code: defn.Code.String(),
248244
Divisibility: uint32(defn.Divisibility),
249245
}
246+
payment.AmountCurrency = &pb.CurrencyDefinition{
247+
Code: defn.Code.String(),
248+
Divisibility: uint32(defn.Divisibility),
249+
}
250250
} else {
251251
payment.Coin = defn.Code.String()
252252
}
@@ -307,7 +307,11 @@ func prepareModeratedOrderContract(data *repo.PurchaseData, n *OpenBazaarNode, c
307307
payment.RedeemScript = hex.EncodeToString(redeemScript)
308308
payment.Chaincode = hex.EncodeToString(chaincode)
309309
fee := wal.GetFeePerByte(wallet.NORMAL)
310-
contract.BuyerOrder.BigRefundFee = fee.String()
310+
if contract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
311+
contract.BuyerOrder.BigRefundFee = fee.String()
312+
} else {
313+
contract.BuyerOrder.RefundFee = fee.Uint64()
314+
}
311315

312316
err = wal.AddWatchedAddresses(addr)
313317
if err != nil {

qa/purchase_crypto_listing.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ def run_test(self):
5656
if r.status_code != 200:
5757
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory get endpoint failed")
5858

59-
check_amt = "350000000000000000"
60-
if self.vendor_version == 4:
61-
check_amt = 350000000000000000
62-
if resp["ether"]["inventory"] != check_amt:
59+
if int(resp["ether"]["inventory"]) != 350000000000000000:
6360
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory incorrect: %d", resp["ether"]["inventory"])
6461

6562
# get listing hash
@@ -89,7 +86,7 @@ def run_test(self):
8986
payment_address = resp["paymentAddress"]
9087
payment_amount = resp["amount"]
9188
amt = 0
92-
if self.buyer_version == 4:
89+
if self.buyer_version == "v4":
9390
amt = payment_amount
9491
else:
9592
amt = int(payment_amount["amount"])
@@ -136,7 +133,7 @@ def run_test(self):
136133
"feeLevel": "NORMAL",
137134
"requireAssociateOrder": False
138135
}
139-
if self.buyer_version == 4:
136+
if self.buyer_version == "v4":
140137
spend["amount"] = payment_amount
141138
spend["wallet"] = "T" + self.cointype
142139

@@ -205,11 +202,12 @@ def run_test(self):
205202
if r.status_code != 200:
206203
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory get endpoint failed")
207204

208-
check_amt = "340000000000000000"
209-
if self.buyer_version == 4:
210-
check_amt = 340000000000000000
211-
if resp["ether"]["inventory"] != check_amt:
212-
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory incorrect: %d", resp["ether"]["inventory"])
205+
if self.buyer_version == "v4":
206+
if int(resp["ether"]["inventory"]) != 340000000000000000:
207+
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory incorrect: %d", resp["ether"]["inventory"])
208+
if self.vendor_version == "v4":
209+
if int(resp["ether"]["inventory"]) != 350000000:
210+
raise TestFailure("PurchaseCryptoListingTest - FAIL: Inventory incorrect: %d", resp["ether"]["inventory"])
213211

214212
print("PurchaseCryptoListingTest - PASS")
215213

qa/purchase_digital.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def run_test(self):
3838
# post listing to alice
3939
with open('testdata/'+ self.vendor_version +'/digital.json') as listing_file:
4040
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
41-
if self.vendor_version == 4:
41+
if self.vendor_version == "v4":
4242
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
4343
else:
4444
listing_json["item"]["priceCurrency"]["code"] = "t" + self.cointype
@@ -108,7 +108,7 @@ def run_test(self):
108108
"feeLevel": "NORMAL",
109109
"requireAssociateOrder": False
110110
}
111-
if self.buyer_version == 4:
111+
if self.buyer_version == "v4":
112112
spend["amount"] = payment_amount
113113
spend["wallet"] = "T" + self.cointype
114114

qa/purchase_moderated_online.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run_test(self):
6363
# post listing to alice
6464
with open('testdata/'+ self.vendor_version +'/listing.json') as listing_file:
6565
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
66-
if self.vendor_version == 4:
66+
if self.vendor_version == "v4":
6767
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
6868
else:
6969
listing_json["item"]["priceCurrency"]["code"] = "t" + self.cointype
@@ -136,7 +136,7 @@ def run_test(self):
136136
"feeLevel": "NORMAL",
137137
"requireAssociateOrder": False
138138
}
139-
if self.buyer_version == 4:
139+
if self.buyer_version == "v4":
140140
spend["amount"] = payment_amount
141141
spend["wallet"] = "T" + self.cointype
142142

repo/listing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ func (cs ListingCoupons) GetProtobuf() []*pb.Listing_Coupon {
919919
var cspb = make([]*pb.Listing_Coupon, len(cs))
920920
for i, c := range cs {
921921
cspb[i] = &pb.Listing_Coupon{
922-
Title: c.GetTitle(),
922+
Title: c.GetTitle(),
923923
}
924924
if c.GetPercentOff() > 0 {
925925
cspb[i].Discount = &pb.Listing_Coupon_PercentDiscount{

0 commit comments

Comments
 (0)