y-pakorn / flutter_web3

Web3 Ethereum, Etherjs and Wallet Connect wrapper for Flutter Web.
Other
136 stars 46 forks source link

TypeError: Cannot read properties of undefined (reading 'providers') #16

Closed laurowrn closed 3 years ago

laurowrn commented 3 years ago

I'm starting with using the flutter_web3 for development, and something went wrong when I tested my contract. I executed the following test:

main() { test('contract test', () async { final contract = Contract(Constants.contractAddress, Constants.abi, JsonRpcProvider(Constants.infuraProvider)); BigInt balance = await contract.call<BigInt>('getBalance'); expect(balance.toInt(), 0); }); }

Then, this error showed-up in my terminal:

`PS D:\Development\Flutter\web3_application> flutter test --platform chrome 00:01 +0 -1: contract test [E] TypeError: Cannot read properties of undefined (reading 'providers') packages\flutter_web3\src\ethers\ethers.dart.js 1091:69 new
web3_test.dart.js 22:130
c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async web3_test.dart.js 21:59
packages\test_api\src\backend\declarer.dart.js 260:17
c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50
packages\stack_trace\src\stack_zone_specification.dart.js 179:98
packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 179:80
c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1436:47 _rootRunUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1335:19 runUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 160:18 handleValue c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 handleValueCallback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 _propagateToListeners c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 466:9 packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 170:71 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1236:7 runGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1276:23 callback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 ===== asynchronous gap =========================== c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future.dart 1107:42 _asyncCompleteWithErrorCallback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 117:9 runBody c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async web3_test.dart.js 21:59 packages\test_api\src\backend\declarer.dart.js 260:17 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 packages\stack_trace\src\stack_zone_specification.dart.js 179:98 packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 179:80 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1436:47 _rootRunUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1335:19 runUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 160:18 handleValue c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 handleValueCallback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 _propagateToListeners c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 466:9 packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 170:71 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1236:7 runGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1276:23 callback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 ===== asynchronous gap =========================== c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1356:19 registerUnaryCallback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 67:19 _async packages\test_api\src\backend\declarer.dart.js 258:69 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1862:67 _runZoned c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1785:10 runZoned packages\test_api\src\backend\declarer.dart.js 258:21 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async packages\test_api\src\backend\declarer.dart.js 248:95 packages\test_api\src\backend\declarer.dart.js 683:15 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async packages\test_api\src\backend\declarer.dart.js 680:61 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1862:67 _runZoned c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1785:10 runZoned packages\test_api\src\backend\declarer.dart.js 680:13 [_waitForOutstandingCallbacks] packages\test_api\src\backend\declarer.dart.js 765:53 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 packages\stack_trace\src\stack_zone_specification.dart.js 179:98 packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 179:80 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1436:47 _rootRunUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1335:19 runUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 160:18 handleValue c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 handleValueCallback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 _propagateToListeners c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 593:7 [_complete] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future.dart 252:15 packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 170:71 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1420:47 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1236:7 runGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1276:23 packages\stack_trace\src\stack_zone_specification.dart.js 247:16 [_run] packages\stack_trace\src\stack_zone_specification.dart.js 170:71 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1260:23 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback ===== asynchronous gap =========================== c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1356:19 registerUnaryCallback c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 67:19 _async packages\test_api\src\backend\declarer.dart.js 762:65 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1862:67 _runZoned c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1785:10 runZoned packages\test_api\src\backend\declarer.dart.js 762:17 packages\test_api\src\backend\declarer.dart.js 790:9 [_guardIfGuarded] packages\test_api\src\backend\declarer.dart.js 761:30 packages\stack_trace\src\stack_zone_specification.dart.js 1272:18 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1862:67 _runZoned c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1785:10 runZoned packages\stack_trace\src\stack_zone_specification.dart.js 1270:20 capture packages\test_api\src\backend\declarer.dart.js 760:19 [_onRun] packages\test_api\src\backend\live_test_controller.dart.js 162:20 run packages\test_api\src\backend\remote_listener.dart.js 232:18 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1428:13 _rootRun c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1328:19 run c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1862:67 _runZoned c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1785:10 runZoned packages\test_api\src\backend\remote_listener.dart.js 231:13 [_runLiveTest] packages\test_api\src\backend\remote_listener.dart.js 207:27 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1436:47 _rootRunUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1335:19 runUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1244:7 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 341:11 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 271:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 733:19 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 607:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 554:5 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1444:13 _rootRunUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1335:19 runUnary c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1244:7 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 341:11 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 271:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 733:19 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 607:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 554:5 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 826:13 add packages\stream_channel\src\stream_channel_controller.dart.js 1293:24 add packages\stream_channel\src\stream_channel_controller.dart.js 502:33 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1620:10 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/internal/async_cast.dart 85:11 [_onData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1620:10 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 341:11 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 271:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 733:19 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 607:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 554:5 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1620:10 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 341:11 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 271:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 733:19 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 607:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 554:5 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 826:13 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1620:10 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 341:11 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 271:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 733:19 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 607:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 554:5 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1620:10 runUnaryGuarded c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 341:11 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_impl.dart 271:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 733:19 [_sendData] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 607:7 [_add] c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 554:5 add c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_controller.dart 826:13 add packages\stream_channel\src\stream_channel_controller.dart.js 1293:24 add web3_test.dart.test.dart.js 83:31 c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall c:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37268:58

00:01 +0 -1: Some tests failed.`

However, when I'm executing this code on my app (using a Floating Action Button), it works normally.

floatingActionButton: FloatingActionButton( onPressed: () async { final contract = Contract(Constants.contractAddress, Constants.abi, JsonRpcProvider(Constants.infuraProvider)); BigInt balance = await contract.call<BigInt>('getBalance'); setState(() { _counter = balance.toInt(); }); }, child: const Icon(Icons.add), ),

I want to know if this is a bug or I am doing something wrong.

y-pakorn commented 3 years ago

Unit test will fail since Javascript dependency was injected through Flutter web's entrypoint (index.html). Not the part of the package itself.

Consider using an integration test or other test suite that ran through web server, not object specific like unit test.