<commit_before>package migrations_test

import (
	"encoding/json"
	"io/ioutil"
	"os"
	"regexp"
	"testing"

	"github.com/OpenBazaar/openbazaar-go/repo/migrations"
	"github.com/OpenBazaar/openbazaar-go/schema"
)

const preMigration016Config = `{
	"OtherConfigProperty1": [1, 2, 3],
	"OtherConfigProperty2": "abc123",
	"Wallets":{
		"BTC": {
			"API": [
					"https://btc.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tbtc.api.openbazaar.org/api"
			]
		},
		"BCH": {
			"API": [
					"https://bch.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tbch.api.openbazaar.org/api"
			]
		},
		"LTC": {
			"API": [
					"https://ltc.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tltc.api.openbazaar.org/api"
			]
		},
		"ZEC": {
			"API": [
					"https://zec.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tzec.api.openbazaar.org/api"
			]
		}
	}
}`

const postMigration016Config = `{
	"OtherConfigProperty1": [1, 2, 3],
	"OtherConfigProperty2": "abc123",
	"Wallets": {
		"BTC": {
			"Type": "API",
			"API": [
					"https://btc.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tbtc.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "https://btc.fees.openbazaar.org",
			"HighFeeDefault": 50,
			"MediumFeeDefault": 10,
			"LowFeeDefault": 1,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"BCH": {
			"Type": "API",
			"API": [
				"https://bch.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
				"https://tbch.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 10,
			"MediumFeeDefault": 5,
			"LowFeeDefault": 1,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"LTC": {
			"Type": "API",
			"API": [
				"https://ltc.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
				"https://tltc.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 20,
			"MediumFeeDefault": 10,
			"LowFeeDefault": 5,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"ZEC": {
			"Type": "API",
			"API": [
				"https://zec.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
				"https://tzec.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 20,
			"MediumFeeDefault": 10,
			"LowFeeDefault": 5,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"ETH": {
			"Type": "API",
			"API": [
				"https://rinkeby.infura.io"
			],
			"APITestnet": [
				"https://rinkeby.infura.io"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 30,
			"MediumFeeDefault": 15,
			"LowFeeDefault": 7,
			"TrustedPeer": "",
			"WalletOptions": {
				"RegistryAddress": "0x403d907982474cdd51687b09a8968346159378f3",
				"RinkebyRegistryAddress": "0x403d907982474cdd51687b09a8968346159378f3",
				"RopstenRegistryAddress": "0x403d907982474cdd51687b09a8968346159378f3"
			}
		}
	}
}`

func migration016AssertAPI(t *testing.T, actual interface{}, expected string) {
	actualSlice := actual.([]interface{})
	if len(actualSlice) != 1 || actualSlice[0] != expected {
		t.Fatalf("incorrect api endpoint.\n\twanted: %s\n\tgot: %s\n", expected, actual)
	}
}

func TestMigration016(t *testing.T) {
	var testRepo, err = schema.NewCustomSchemaManager(schema.SchemaContext{
		DataPath:        schema.GenerateTempPath(),<commit_msg>Fix testnet to mainnet<commit_after>package migrations_test

import (
	"encoding/json"
	"io/ioutil"
	"os"
	"regexp"
	"testing"

	"github.com/OpenBazaar/openbazaar-go/repo/migrations"
	"github.com/OpenBazaar/openbazaar-go/schema"
)

const preMigration016Config = `{
	"OtherConfigProperty1": [1, 2, 3],
	"OtherConfigProperty2": "abc123",
	"Wallets":{
		"BTC": {
			"API": [
					"https://btc.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tbtc.api.openbazaar.org/api"
			]
		},
		"BCH": {
			"API": [
					"https://bch.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tbch.api.openbazaar.org/api"
			]
		},
		"LTC": {
			"API": [
					"https://ltc.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tltc.api.openbazaar.org/api"
			]
		},
		"ZEC": {
			"API": [
					"https://zec.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tzec.api.openbazaar.org/api"
			]
		}
	}
}`

const postMigration016Config = `{
	"OtherConfigProperty1": [1, 2, 3],
	"OtherConfigProperty2": "abc123",
	"Wallets": {
		"BTC": {
			"Type": "API",
			"API": [
					"https://btc.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
					"https://tbtc.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "https://btc.fees.openbazaar.org",
			"HighFeeDefault": 50,
			"MediumFeeDefault": 10,
			"LowFeeDefault": 1,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"BCH": {
			"Type": "API",
			"API": [
				"https://bch.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
				"https://tbch.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 10,
			"MediumFeeDefault": 5,
			"LowFeeDefault": 1,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"LTC": {
			"Type": "API",
			"API": [
				"https://ltc.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
				"https://tltc.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 20,
			"MediumFeeDefault": 10,
			"LowFeeDefault": 5,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"ZEC": {
			"Type": "API",
			"API": [
				"https://zec.blockbook.api.openbazaar.org/api"
			],
			"APITestnet": [
				"https://tzec.blockbook.api.openbazaar.org/api"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 20,
			"MediumFeeDefault": 10,
			"LowFeeDefault": 5,
			"TrustedPeer": "",
			"WalletOptions": null
		},
		"ETH": {
			"Type": "API",
			"API": [
				"https://mainnet.infura.io"
			],
			"APITestnet": [
				"https://rinkeby.infura.io"
			],
			"MaxFee": 200,
			"FeeAPI": "",
			"HighFeeDefault": 30,
			"MediumFeeDefault": 15,
			"LowFeeDefault": 7,
			"TrustedPeer": "",
			"WalletOptions": {
				"RegistryAddress": "0x403d907982474cdd51687b09a8968346159378f3",
				"RinkebyRegistryAddress": "0x403d907982474cdd51687b09a8968346159378f3",
				"RopstenRegistryAddress": "0x403d907982474cdd51687b09a8968346159378f3"
			}
		}
	}
}`

func migration016AssertAPI(t *testing.T, actual interface{}, expected string) {
	actualSlice := actual.([]interface{})
	if len(actualSlice) != 1 || actualSlice[0] != expected {
		t.Fatalf("incorrect api endpoint.\n\twanted: %s\n\tgot: %s\n", expected, actual)
	}
}

func TestMigration016(t *testing.T) {
	var testRepo, err = schema.NewCustomSchemaManager(schema.SchemaContext{
		DataPath:        schema.GenerateTempPath(),
{'fraction_non_alphanumeric': 0.20062323786912004, 'fraction_numerical': 0.05074936934263244, 'mean_word_length': 3.1811414392059554, 'pattern_counts': {'":': 152, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 38, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851979', 'n_tokens_mistral': 3595, 'n_tokens_neox': 2892, 'n_words': 360}