testContract method

Future<bool> testContract({
  1. String? code,
  2. List? init,
  3. int? version,
})

Implementation

Future<bool> testContract({String? code, List? init, int? version}) async {
  TestScilla contract = new TestScilla(
      params: {'code': code, 'init': init, 'version': version},
      messenger: this.messenger,
      status: ContractStatus.INITIALISED);
  Map result = await contract
      // decode ABI from code first
      .decodeABI(code: code)
      // we set the init params to decoded ABI
      .then((decoded) => decoded.setInitParamsValues(
          decoded.abi!.getInitParams()!,
          init as List<Map<dynamic, dynamic>>?))
      // we get the current block number from node, and set it to params
      .then((inited) => inited.setBlockNumber(null))
      // but we have to give it a test
      .then((ready) => ready.testCall(2000))
      // now we change the status to wait for sign
      .then((state) => state.status == ContractStatus.TESTED
          ? {'abi': state.abi, 'init': state.init, 'status': state.status}
          : {
              'abi': state.abi,
              'init': state.init,
              'status': ContractStatus.ERROR,
            });
  return result['status'] == ContractStatus.TESTED;
}