-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issues with relayUrl not being used and fixed false positive tests
- Loading branch information
Sterling Long
committed
Aug 8, 2023
1 parent
5ffe1ea
commit f6c90f1
Showing
6 changed files
with
149 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:walletconnect_flutter_v2/apis/core/relay_client/relay_client.dart'; | ||
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; | ||
|
||
import '../shared/shared_test_utils.dart'; | ||
import '../shared/shared_test_utils.mocks.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('Core throws errors', () { | ||
test('on start if there is no internet connection', () async { | ||
final MockWebSocketHandler mockWebSocketHandler = MockWebSocketHandler(); | ||
when(mockWebSocketHandler.connect()).thenThrow(const WalletConnectError( | ||
code: -1, | ||
message: 'No internet connection: test', | ||
)); | ||
|
||
ICore core = Core( | ||
projectId: 'abc', | ||
memoryStore: true, | ||
); | ||
core.relayClient = RelayClient( | ||
core: core, | ||
messageTracker: getMessageTracker(core: core), | ||
topicMap: getTopicMap(core: core), | ||
socketHandler: mockWebSocketHandler, | ||
); | ||
|
||
try { | ||
await core.start(); | ||
expect(true, false); | ||
} on WalletConnectError catch (e) { | ||
expect(e.message, 'No internet connection: test'); | ||
} | ||
|
||
verifyInOrder([ | ||
mockWebSocketHandler.setup( | ||
url: argThat( | ||
contains( | ||
WalletConnectConstants.DEFAULT_RELAY_URL, | ||
), | ||
named: 'url', | ||
), | ||
), | ||
mockWebSocketHandler.connect(), | ||
mockWebSocketHandler.setup( | ||
url: argThat( | ||
contains( | ||
WalletConnectConstants.FALLBACK_RELAY_URL, | ||
), | ||
named: 'url', | ||
), | ||
), | ||
mockWebSocketHandler.connect(), | ||
]); | ||
|
||
const testRelayUrl = 'wss://relay.test.com'; | ||
core = Core( | ||
projectId: 'abc', | ||
memoryStore: true, | ||
relayUrl: testRelayUrl, | ||
); | ||
core.relayClient = RelayClient( | ||
core: core, | ||
messageTracker: getMessageTracker(core: core), | ||
topicMap: getTopicMap(core: core), | ||
socketHandler: mockWebSocketHandler, | ||
); | ||
|
||
try { | ||
await core.start(); | ||
expect(true, false); | ||
} on WalletConnectError catch (e) { | ||
expect(e.message, 'No internet connection: test'); | ||
} | ||
|
||
// Check that setup was called once for custom URL | ||
verify( | ||
mockWebSocketHandler.setup( | ||
url: argThat( | ||
contains(testRelayUrl), | ||
named: 'url', | ||
), | ||
), | ||
).called(1); | ||
verify(mockWebSocketHandler.connect()).called(1); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters