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

Commit 2791875

Browse files
authored
Merge pull request #2062 from OpenBazaar/brian.fixmigration
Fix lastDisputeExpiryNotifiedAt error
2 parents 7c31fdd + 00158b1 commit 2791875

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

core/profile.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
910
"github.com/OpenBazaar/openbazaar-go/ipfs"
1011
"github.com/OpenBazaar/openbazaar-go/repo"
1112

@@ -361,7 +362,7 @@ func ValidateProfile(profile *pb.Profile) error {
361362
}
362363
}
363364
if profile.ModeratorInfo.Fee != nil {
364-
if profile.ModeratorInfo.Fee.FixedFee != nil &&
365+
if profile.ModeratorInfo.Fee.FeeType != pb.Moderator_Fee_PERCENTAGE && profile.ModeratorInfo.Fee.FixedFee != nil &&
365366
len(profile.ModeratorInfo.Fee.FixedFee.AmountCurrency.Code) > repo.WordMaxCharacters {
366367
return fmt.Errorf("moderator fee currency code character length is greater than the max of %d", repo.WordMaxCharacters)
367368
}

repo/buyer_order.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package repo
22

33
import (
4+
"math/big"
5+
46
"github.com/OpenBazaar/openbazaar-go/pb"
57
"github.com/golang/protobuf/proto"
6-
"math/big"
78
)
89

910
// ToV5Order scans through the order looking for any deprecated fields and turns them into their v5 counterpart.
@@ -35,6 +36,10 @@ func ToV5Order(order *pb.Order, lookupFunc func(currencyCode string) (CurrencyDe
3536
newOrder.Payment.Amount = 0
3637
}
3738

39+
if order.Payment.AmountCurrency == nil && order.Payment.Coin == "" {
40+
order.Payment.Coin = "BTC"
41+
}
42+
3843
if order.Payment.Coin != "" && order.Payment.AmountCurrency == nil {
3944
def, err := lookupFunc(order.Payment.Coin)
4045
if err != nil {
@@ -46,5 +51,6 @@ func ToV5Order(order *pb.Order, lookupFunc func(currencyCode string) (CurrencyDe
4651
}
4752
newOrder.Payment.Coin = ""
4853
}
54+
4955
return newOrder, nil
5056
}

repo/buyer_order_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package repo
22

33
import (
4+
"testing"
5+
46
"github.com/OpenBazaar/jsonpb"
57
"github.com/OpenBazaar/openbazaar-go/pb"
6-
"testing"
78
)
89

910
func TestToV5Order(t *testing.T) {
@@ -22,7 +23,7 @@ func TestToV5Order(t *testing.T) {
2223
RefundFee: 1000,
2324
Payment: &pb.Order_Payment{},
2425
},
25-
expected: `{"payment":{"method":"ADDRESS_REQUEST"},"bigRefundFee":"1000"}`,
26+
expected: `{"payment":{"method":"ADDRESS_REQUEST","amountCurrency":{"code":"BTC","divisibility":8}},"bigRefundFee":"1000"}`,
2627
},
2728
{
2829
name: "item quantity test",
@@ -34,7 +35,7 @@ func TestToV5Order(t *testing.T) {
3435
},
3536
Payment: &pb.Order_Payment{},
3637
},
37-
expected: `{"items":[{"bigQuantity":"19"}],"payment":{"method":"ADDRESS_REQUEST"}}`,
38+
expected: `{"items":[{"bigQuantity":"19"}],"payment":{"method":"ADDRESS_REQUEST","amountCurrency":{"code":"BTC","divisibility":8}}}`,
3839
},
3940
{
4041
name: "item quantity64 test",
@@ -46,7 +47,7 @@ func TestToV5Order(t *testing.T) {
4647
},
4748
Payment: &pb.Order_Payment{},
4849
},
49-
expected: `{"items":[{"bigQuantity":"19"}],"payment":{"method":"ADDRESS_REQUEST"}}`,
50+
expected: `{"items":[{"bigQuantity":"19"}],"payment":{"method":"ADDRESS_REQUEST","amountCurrency":{"code":"BTC","divisibility":8}}}`,
5051
},
5152
{
5253
name: "payment amount test",
@@ -55,7 +56,7 @@ func TestToV5Order(t *testing.T) {
5556
Amount: 2000,
5657
},
5758
},
58-
expected: `{"payment":{"method":"ADDRESS_REQUEST","bigAmount":"2000"}}`,
59+
expected: `{"payment":{"method":"ADDRESS_REQUEST","bigAmount":"2000","amountCurrency":{"code":"BTC","divisibility":8}}}`,
5960
},
6061
{
6162
name: "payment amount currency",
@@ -78,7 +79,6 @@ func TestToV5Order(t *testing.T) {
7879
if err != nil {
7980
t.Errorf("Test %s marshalling failed: %s", test.name, err)
8081
}
81-
8282
if out != test.expected {
8383
t.Errorf("Test %s incorrect output: Expected %s, got %s", test.name, test.expected, out)
8484
}

repo/migrations/Migration029.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
AM02_insert_sales = "INSERT INTO sales SELECT orderID, contract, state, read, timestamp, total, thumbnail, buyerID, buyerHandle, title, shippingName, shippingAddress, paymentAddr, funded, transactions, lastDisputeTimeoutNotifiedAt, coinType, paymentCoin FROM temp_sales;"
1818
AM02_drop_temp_sales = "DROP TABLE temp_sales;"
1919

20+
AM02_up_update_purchases = "update purchases set lastDisputeExpiryNotifiedAt = 0 where lastDisputeExpiryNotifiedAt is NULL;"
2021
AM02_up_create_purchases = "create table purchases (orderID text primary key not null, contract blob, state integer, read integer, timestamp integer, total text, thumbnail text, vendorID text, vendorHandle text, title text, shippingName text, shippingAddress text, paymentAddr text, funded integer, transactions blob, lastDisputeTimeoutNotifiedAt integer not null default 0, lastDisputeExpiryNotifiedAt integer not null default 0, disputedAt integer not null default 0, coinType not null default '', paymentCoin not null default '');"
2122
AM02_down_create_purchases = "create table purchases (orderID text primary key not null, contract blob, state integer, read integer, timestamp integer, total integer, thumbnail text, vendorID text, vendorHandle text, title text, shippingName text, shippingAddress text, paymentAddr text, funded integer, transactions blob, lastDisputeTimeoutNotifiedAt integer not null default 0, lastDisputeExpiryNotifiedAt integer not null default 0, disputedAt integer not null default 0, coinType not null default '', paymentCoin not null default '');"
2223
AM02_temp_purchases = "ALTER TABLE purchases RENAME TO temp_purchases;"
@@ -56,6 +57,7 @@ func (AM02) Up(repoPath string, dbPassword string, testnet bool) error {
5657
}
5758

5859
upSequence := strings.Join([]string{
60+
AM02_up_update_purchases,
5961
AM02_temp_sales,
6062
AM02_up_create_sales,
6163
AM02_insert_sales,

repo/migrations/Migration029_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var stmt = `PRAGMA key = 'letmein';
2424
vendorID text, vendorHandle text, title text,
2525
shippingName text, shippingAddress text, paymentAddr text,
2626
funded integer, transactions blob,
27-
lastDisputeTimeoutNotifiedAt integer not null default 0,
28-
lastDisputeExpiryNotifiedAt integer not null default 0,
27+
lastDisputeTimeoutNotifiedAt integer default 0,
28+
lastDisputeExpiryNotifiedAt integer default 0,
2929
disputedAt integer not null default 0, coinType not null default '',
3030
paymentCoin not null default '');
3131
create table inventory (invID text primary key not null, slug text, variantIndex integer, count integer);`
@@ -52,7 +52,7 @@ func TestMigration029(t *testing.T) {
5252
if _, err := db.Exec("INSERT INTO sales (orderID, total) values (?,?)", "asdf", 3); err != nil {
5353
t.Fatal(err)
5454
}
55-
if _, err := db.Exec("INSERT INTO purchases (orderID, total) values (?,?)", "asdf", 3); err != nil {
55+
if _, err := db.Exec("INSERT INTO purchases (orderID, total, lastDisputeExpiryNotifiedAt) values (?,?, NULL)", "asdf", 3); err != nil {
5656
t.Fatal(err)
5757
}
5858
if _, err := db.Exec("INSERT INTO inventory (invID, count) values (?,?)", "asdf", "3"); err != nil {

0 commit comments

Comments
 (0)