Exemple #1
0
        public async Task <TContract> Deploy()
        {
            var txParams = await GetTransactionParams();

            var contractAddr = await ContractFactory.Deploy(_contractAttribute, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);

            var contractInstance = new TContract();

            contractInstance.Setup(_rpcClient, contractAddr, _defaultFromAccount ?? txParams.From.Value);
            return(contractInstance);
        }
Exemple #2
0
        /// <summary>
        /// Creates new contract deployment transaction and expects a revert.
        /// Throws an exception if transaction does not revert.
        /// </summary>
        public async Task ExpectRevert()
        {
            var txParams = await GetTransactionParams();

            (JsonRpcError error, Hash transactionHash) = await ContractFactory.TryDeploy(_contractAttribute, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);

            if (error == null)
            {
                var receipt = await _rpcClient.GetTransactionReceipt(transactionHash);

                if (receipt == null)
                {
                    throw new Exception($"Expected contract deployment transaction to revert, but server node did not return a transaction receipt for transaction hash: {transactionHash}");
                }

                if (receipt.Status != 0)
                {
                    throw new Exception($"Expected contract deployment transaction to revert");
                }
            }
        }