2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:stackwallet/utilities/address_utils.dart';
|
2024-05-15 21:39:43 +00:00
|
|
|
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
const String firoAddress = "a6ESWKz7szru5syLtYAPRhHLdKvMq3Yt1j";
|
|
|
|
|
|
|
|
test("condense address", () {
|
|
|
|
final condensedAddress = AddressUtils.condenseAddress(firoAddress);
|
|
|
|
expect(condensedAddress, "a6ESW...3Yt1j");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("parse a valid uri string A", () {
|
|
|
|
const uri = "dogecoin:$firoAddress?amount=50&label=eggs";
|
2024-11-18 20:14:25 +00:00
|
|
|
final result = AddressUtils.parsePaymentUri(uri);
|
|
|
|
expect(result, isNotNull);
|
|
|
|
expect(result!.scheme, "dogecoin");
|
|
|
|
expect(result.address, firoAddress);
|
|
|
|
expect(result.amount, "50");
|
|
|
|
expect(result.label, "eggs");
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("parse a valid uri string B", () {
|
|
|
|
const uri = "firo:$firoAddress?amount=50&message=eggs+are+good";
|
2024-11-18 20:14:25 +00:00
|
|
|
final result = AddressUtils.parsePaymentUri(uri);
|
|
|
|
expect(result, isNotNull);
|
|
|
|
expect(result!.scheme, "firo");
|
|
|
|
expect(result.address, firoAddress);
|
|
|
|
expect(result.amount, "50");
|
|
|
|
expect(result.message, "eggs are good");
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("parse a valid uri string C", () {
|
|
|
|
const uri = "bitcoin:$firoAddress?amount=50.1&message=eggs%20are%20good%21";
|
2024-11-18 20:14:25 +00:00
|
|
|
final result = AddressUtils.parsePaymentUri(uri);
|
|
|
|
expect(result, isNotNull);
|
|
|
|
expect(result!.scheme, "bitcoin");
|
|
|
|
expect(result.address, firoAddress);
|
|
|
|
expect(result.amount, "50.1");
|
|
|
|
expect(result.message, "eggs are good!");
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("parse an invalid uri string", () {
|
|
|
|
const uri = "firo$firoAddress?amount=50&label=eggs";
|
2024-11-18 20:14:25 +00:00
|
|
|
final result = AddressUtils.parsePaymentUri(uri);
|
|
|
|
expect(result, isNull);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("parse an invalid string", () {
|
|
|
|
const uri = "$firoAddress?amount=50&label=eggs";
|
2024-11-18 20:14:25 +00:00
|
|
|
final result = AddressUtils.parsePaymentUri(uri);
|
|
|
|
expect(result, isNull);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("parse an invalid uri string", () {
|
|
|
|
const uri = "::: 8 \\ %23";
|
2024-11-18 20:14:25 +00:00
|
|
|
expect(AddressUtils.parsePaymentUri(uri), isNull);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("encode a list of (mnemonic) words/strings as a json object", () {
|
|
|
|
final List<String> list = [
|
|
|
|
"hello",
|
|
|
|
"word",
|
|
|
|
"something",
|
|
|
|
"who",
|
|
|
|
"green",
|
2024-05-15 21:39:43 +00:00
|
|
|
"seven",
|
2022-08-26 08:11:35 +00:00
|
|
|
];
|
|
|
|
final result = AddressUtils.encodeQRSeedData(list);
|
2024-05-15 21:39:43 +00:00
|
|
|
expect(
|
|
|
|
result,
|
|
|
|
'{"mnemonic":["hello","word","something","who","green","seven"]}',
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("decode a valid json string to Map<String, dynamic>", () {
|
|
|
|
const jsonString =
|
|
|
|
'{"mnemonic":["hello","word","something","who","green","seven"]}';
|
|
|
|
final result = AddressUtils.decodeQRSeedData(jsonString);
|
|
|
|
expect(result, {
|
2024-05-15 21:39:43 +00:00
|
|
|
"mnemonic": ["hello", "word", "something", "who", "green", "seven"],
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("decode an invalid json string to Map<String, dynamic>", () {
|
|
|
|
const jsonString =
|
|
|
|
'{"mnemonic":"hello","word","something","who","green","seven"]}';
|
|
|
|
|
|
|
|
expect(AddressUtils.decodeQRSeedData(jsonString), {});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("build a uri string with empty params", () {
|
2024-05-15 21:39:43 +00:00
|
|
|
expect(
|
|
|
|
AddressUtils.buildUriString(
|
2024-10-18 22:55:27 +00:00
|
|
|
Firo(CryptoCurrencyNetwork.main).uriScheme, firoAddress, {}),
|
2024-05-15 21:39:43 +00:00
|
|
|
"firo:$firoAddress",
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("build a uri string with one param", () {
|
|
|
|
expect(
|
2024-05-15 21:39:43 +00:00
|
|
|
AddressUtils.buildUriString(
|
2024-10-18 22:55:27 +00:00
|
|
|
Firo(CryptoCurrencyNetwork.main).uriScheme,
|
2024-05-15 21:39:43 +00:00
|
|
|
firoAddress,
|
|
|
|
{"amount": "10.0123"},
|
|
|
|
),
|
|
|
|
"firo:$firoAddress?amount=10.0123",
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("build a uri string with some params", () {
|
|
|
|
expect(
|
2024-05-15 21:39:43 +00:00
|
|
|
AddressUtils.buildUriString(
|
2024-10-18 22:55:27 +00:00
|
|
|
Firo(CryptoCurrencyNetwork.main).uriScheme,
|
2024-05-15 21:39:43 +00:00
|
|
|
firoAddress,
|
|
|
|
{"amount": "10.0123", "message": "Some kind of message!"},
|
|
|
|
),
|
|
|
|
"firo:$firoAddress?amount=10.0123&message=Some+kind+of+message%21",
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
}
|