Skip to content

Commit b1ca944

Browse files
author
Ed Gamble
committed
Merge branch 'refs/heads/develop' into feature/CORE-525
2 parents c6e8a9a + 973b0f1 commit b1ca944

File tree

7 files changed

+55
-30
lines changed

7 files changed

+55
-30
lines changed

Java/CoreCrypto/src/androidTest/java/com/breadwallet/corecrypto/AmountAIT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ public void testAmountCreateEth() {
160160
assertTrue(a4.doubleAmount(ether_eth).isPresent());
161161
assertEquals(new Double(123.12345678), a4.doubleAmount(gwei_eth).get());
162162

163-
Amount a5 = Amount.create( "1.234567891234567891", false, ether_eth).get();
164-
assertEquals(new Double(1234567891234567891L), a5.doubleAmount(wei_eth).get());
165-
// TODO(discuss): The swift behaviour diverges here; how do we want to handle?
166-
// assertEquals("wei1,234,567,891,234,570,000", a5.toStringAsUnit(wei_eth, null).get());
167-
assertEquals("1234567891234567891", a5.toStringWithBase(10, ""));
163+
Amount a5 = Amount.create( "1.234567891234567936", false, ether_eth).get();
164+
assertEquals(new Double(1234567891234567936L), a5.doubleAmount(wei_eth).get());
165+
assertEquals("1234567891234567936", a5.toStringWithBase(10, ""));
166+
// TODO(discuss): The swift behaviour diverges here (rounds to ..."568,000:); does that matter?
167+
assertEquals("wei1,234,567,891,234,567,940", a5.toStringAsUnit(wei_eth, null).get());
168168

169169
Amount a6 = Amount.create("1", false, ether_eth).get();
170170
assertEquals("1000000000000000000", a6.toStringWithBase(10, ""));
@@ -178,10 +178,7 @@ public void testAmountCreateEth() {
178178

179179
Amount a8 = Amount.create("123456789012345678.0", false, wei_eth).get();
180180
assertEquals("123456789012345678", a8.toStringWithBase(10, ""));
181-
// TODO(discuss): The swift behaviour diverges here; how do we want to handle?
182-
// assertEquals("wei123,456,789,012,345,600", a8.toStringAsUnit(wei_eth).get());
183181
assertEquals("wei123,456,789,012,345,680", a8.toStringAsUnit(wei_eth).get());
184-
assertNotEquals("wei123,456,789,012,345,678", a8.toStringAsUnit(wei_eth).get());
185182

186183
double a8Double = a8.doubleAmount(wei_eth).get();
187184
assertEquals(1.2345678901234568e17, a8Double, 0.0);

Java/CoreCrypto/src/main/java/com/breadwallet/corecrypto/System.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,12 @@ static void wipeAll(String storagePath, List<com.breadwallet.crypto.System> exem
281281
}
282282

283283
File storageFile = new File(storagePath);
284-
for (File child : storageFile.listFiles()) {
285-
if (!exemptSystemPath.contains(child.getAbsolutePath())) {
286-
deleteRecursively(child);
284+
File[] childFiles = storageFile.listFiles();
285+
if (null != childFiles) {
286+
for (File child : childFiles) {
287+
if (!exemptSystemPath.contains(child.getAbsolutePath())) {
288+
deleteRecursively(child);
289+
}
287290
}
288291
}
289292
}

Java/Crypto/src/main/java/com/breadwallet/crypto/System.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ static void wipe(System system) {
100100

101101
/**
102102
* Remove (aka 'wipe') the persistent storage associated with any and all systems located
103-
* within `atPath` except for a specified array of systems to preserve. Generally, this
103+
* within `storagePath` except for a specified array of systems to preserve. Generally, this
104104
* function should be called on startup after all systems have been created. When called at
105105
* that time, any 'left over' systems will have their persistent storeage wiped.
106106
*
107+
* Note: This function will perform no action if `storagePath` does not exist or is
108+
* not a directory.
109+
*
107110
* @param storagePath the file system path where system data is persistently stored
108111
* @param exemptSystems the list of systems that should not have their data wiped.
109112
*/

Swift/BRCrypto/BRCryptoSystem.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,10 @@ public final class System {
10081008
/// Remove (aka 'wipe') the persistent storage associated with any and all systems located
10091009
/// within `atPath` except for a specified array of systems to preserve. Generally, this
10101010
/// function should be called on startup after all systems have been created. When called at
1011-
/// that time, any 'left over' systems will have their persistent storeage wiped.
1011+
/// that time, any 'left over' systems will have their persistent storeage wiped.
1012+
///
1013+
/// - Note: This function will perform no action if `atPath` does not exist or is
1014+
/// not a directory.
10121015
///
10131016
/// - Parameter atPath: the file system path where system data is persistently stored
10141017
/// - Parameter systems: the array of systems that shouldn not have their data wiped.

Swift/BRCryptoTests/BRCryptoAmountTests.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class BRCryptoAmountTests: XCTestCase {
225225
}
226226

227227
func testAmountETH () {
228+
var result: String! = nil
228229
let eth = Currency (uids: "Ethereum", name: "Ethereum", code: "ETH", type: "native", issuer: nil)
229230

230231
let ETH_WEI = BRCrypto.Unit (currency: eth, uids: "ETH-WEI", name: "WEI", symbol: "wei")
@@ -251,36 +252,39 @@ class BRCryptoAmountTests: XCTestCase {
251252
XCTAssertNotNil(a4!.double (as: ETH_GWEI))
252253
XCTAssertEqual(123.12345678, a4!.double (as: ETH_GWEI)!)
253254

254-
255-
let a5 = Amount.create(string: "1.234567891234567891", negative: false, unit: ETH_ETHER)
255+
// Avoid a 'exact double' representation error:
256+
// was 1.234567891234567891, now: 1.234567891234567936
257+
let a5 = Amount.create(string: "1.234567891234567936", negative: false, unit: ETH_ETHER)
256258
XCTAssertNotNil(a5)
257259
XCTAssertNotNil (a5?.double(as: ETH_WEI))
258-
XCTAssertEqual(1234567891234567891, a5?.double(as: ETH_WEI)!)
260+
XCTAssertEqual(1234567891234567936, a5?.double(as: ETH_WEI)!)
261+
XCTAssertEqual("1234567891234567936", a5?.string (base: 10, preface: ""))
259262
// Lost precision - last 5 digits
260-
if #available(iOS 13, *) {
261-
XCTAssertEqual("wei 1,234,567,891,234,568,000", a5?.string(as: ETH_WEI)!)
262-
}
263-
else {
264-
XCTAssertEqual("wei1,234,567,891,234,570,000", a5?.string(as: ETH_WEI)!)
265-
}
263+
if #available(iOS 13, *) { result = "wei 1,234,567,891,234,568,000" }
264+
else { result = "wei1,234,567,891,234,570,000" }
265+
XCTAssertEqual(result, a5?.string(as: ETH_WEI)!)
266266

267-
XCTAssertEqual("1234567891234567891", a5?.string (base: 10, preface: ""))
268267
XCTAssertEqual("1000000000000000000", Amount.create(string: "1", negative: false, unit: ETH_ETHER)!.string (base: 10, preface: ""))
269268
// String (1000000000000000000, radix:16, uppercase: true) -> DE0B6B3A7640000
270269
XCTAssertEqual("0xDE0B6B3A7640000".lowercased(), Amount.create(string: "1", negative: false, unit: ETH_ETHER)!.string (base: 16, preface: "0x"))
271270

272271
let a6 = Amount.create(string: "123000000000000000000.0", negative: false, unit: ETH_WEI)
273272
XCTAssertNotNil(a6)
274-
XCTAssertEqual("wei123,000,000,000,000,000,000", a6?.string(as: ETH_WEI)!)
273+
if #available(iOS 13, *) { result = "wei 123,000,000,000,000,000,000" }
274+
else { result = "wei123,000,000,000,000,000,000" }
275+
XCTAssertEqual(result, a6?.string(as: ETH_WEI)!)
275276

276277
let a6Double = a6?.double (as: ETH_WEI)
277278
XCTAssertEqual(a6Double, 1.23e20)
278279

279280
let a7 = Amount.create(string: "123456789012345678.0", negative: false, unit: ETH_WEI)
280281
XCTAssertNotNil(a7)
281282
XCTAssertEqual ("123456789012345678", a7?.string(base: 10, preface: ""))
282-
XCTAssertEqual ("wei123,456,789,012,346,000", a7?.string(as: ETH_WEI)!)
283-
XCTAssertNotEqual("wei123,456,789,012,345,678", a7?.string(as: ETH_WEI)!)
283+
// Note: a DIFFERENT VALUE between iOS 13
284+
if #available(iOS 13, *) { result = "wei 123,456,789,012,345,680" }
285+
else { result = "wei123,456,789,012,346,000" }
286+
XCTAssertEqual (result, a7?.string(as: ETH_WEI)!)
287+
// XCTAssertNotEqual("wei123,456,789,012,345,678", a7?.string(as: ETH_WEI)!)
284288

285289
let a7Double = a7?.double(as: ETH_WEI)
286290
XCTAssertEqual(a7Double, 1.2345678901234568e17)

bitcoin/BRWalletManager.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,9 +1816,24 @@ _BRWalletManagerSyncEvent(void * context,
18161816
}
18171817
case SYNC_MANAGER_SET_PEERS: {
18181818
// filesystem changes are NOT queued; they are acted upon immediately
1819-
fileServiceReplace (bwm->fileService, fileServiceTypePeers,
1820-
(const void **) event.u.peers.peers,
1821-
event.u.peers.count);
1819+
if (0 == event.u.peers.count) {
1820+
// no peers to set, just do a clear
1821+
fileServiceClear (bwm->fileService, fileServiceTypePeers);
1822+
} else {
1823+
// fileServiceReplace expects an array of pointers to entities, instead of an array of
1824+
// structures so let's do the conversion here
1825+
BRPeer **peers = calloc (event.u.peers.count,
1826+
sizeof(BRPeer *));
1827+
1828+
for (size_t i = 0; i < event.u.peers.count; i++) {
1829+
peers[i] = &event.u.peers.peers[i];
1830+
}
1831+
1832+
fileServiceReplace (bwm->fileService, fileServiceTypePeers,
1833+
(const void **) peers,
1834+
event.u.peers.count);
1835+
free (peers);
1836+
}
18221837
break;
18231838
}
18241839
case SYNC_MANAGER_ADD_PEERS: {

bitcoin/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ int BRWalletTests()
24642464
if (BRWalletBalance(w) != SATOSHIS)
24652465
r = 0, fprintf(stderr, "***FAILED*** %s: BRWalletNew() test\n", __func__);
24662466

2467-
if (BRWalletAllAddrs(w, NULL, 0) != SEQUENCE_GAP_LIMIT_EXTERNAL + SEQUENCE_GAP_LIMIT_INTERNAL + 1)
2467+
if (BRWalletAllAddrs(w, NULL, 0) != SEQUENCE_GAP_LIMIT_EXTERNAL_EXTENDED + SEQUENCE_GAP_LIMIT_INTERNAL_EXTENDED + 1)
24682468
r = 0, fprintf(stderr, "***FAILED*** %s: BRWalletAllAddrs() test\n", __func__);
24692469

24702470
UInt256 hash = tx->txHash;

0 commit comments

Comments
 (0)