Electric-Coin-Company / zcash-swift-wallet-sdk

iOS light client Framework proof-of-concept
MIT License
37 stars 33 forks source link

AdvancedReOrg Tests fail when running Lightwalletd on `master` #644

Closed pacu closed 1 year ago

pacu commented 1 year ago

commit 5d174f7feb702dc19aec5b09d8be8b3d5b17ce45 is having problems: xctest[35960:765658] [DEBUG :ladybug:] SDKSynchronizer.swift - reorgDetected(_:) - Line: 371 -> handling reorg at: 419200 with rewind height: 663050

Chlup commented 1 year ago

I found some clues.

The problematic test is testReOrgRemovesIncomingTxForever. Other tests work fine. I found out that the behavior depends on the SDK code and also on the version of the lightwalletd. That's why I was experiencing so strange behavior.

In this commit sleep(1) was added to the testReOrgRemovesIncomingTxForever test. And behavior of the test depends on if this is sleep is there or not. And the behavior is different for each commit of lightwalletd.

Here is how the test behaves for different commits of lightwalletd and different sleeps:

5d174f7feb702dc19aec5b09d8be8b3d5b17ce45 (latest):
- no sleep - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(1) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(2) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(10) - XCTAssertEqual failed: ("663196") is not equal to ("663195")

636a4d9632ff46f147d5793e77b67452c4b4a373:
- no sleep - Failed with error: generalError(message: "block not found in cache, should always be in cache in darkside mode")
- sleep(1) - Failed with error: generalError(message: "block not found in cache, should always be in cache in darkside mode")
- sleep(2) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(10) - XCTAssertEqual failed: ("663196") is not equal to ("663195")

4267cc975414d296bb0cf9eb81929806fe426834:
- no sleep - Failed with error: generalError(message: "block not found in cache, should always be in cache in darkside mode")
- sleep(1) - Failed with error: generalError(message: "block not found in cache, should always be in cache in darkside mode")
- sleep(2) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(10) - XCTAssertEqual failed: ("663196") is not equal to ("663195")

ad5ecda5fbb5e12799f926b8cd785d54fdd250c8:
- no sleep - works
- sleep(1) - works
- sleep(2) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(10) - XCTAssertEqual failed: ("663196") is not equal to ("663195")

v0.4.13:
- no sleep - works
- sleep(1) - works
- sleep(2) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(10) - XCTAssertEqual failed: ("663196") is not equal to ("663195")

v0.4.10:
- no sleep - works
- sleep(1) - works
- sleep(2) - XCTAssertEqual failed: ("663196") is not equal to ("663195")
- sleep(10) - XCTAssertEqual failed: ("663196") is not equal to ("663195")

Difference in behavior is strange. I understand why test doesn't work if the sleep is too low - lightwalletd in darkside mode doesn't have enough time to sync mocked blocks. But I don't understand why too high sleep is the problem. I am even not sure if the problem is in our code or in lightwalletd.

pacu commented 1 year ago

Thanks for this research Michal! there's something going on for sure