mirror of https://github.com/hyperledger/besu
NC-1890: Acceptance test smart contract (#283)
* IoC for deploying the smart contract * Smart contract deploy as a Transaction * Consistent transaction naming * Avoiding a resource leak with lazy creation of Web3j connections
parent
8792c0a00a
commit
ae8dc507ab
@ -0,0 +1,62 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2018 ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
*/ |
||||||
|
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction; |
||||||
|
|
||||||
|
import java.lang.reflect.Method; |
||||||
|
import java.math.BigInteger; |
||||||
|
|
||||||
|
import org.web3j.crypto.Credentials; |
||||||
|
import org.web3j.protocol.Web3j; |
||||||
|
import org.web3j.protocol.core.RemoteCall; |
||||||
|
import org.web3j.tx.Contract; |
||||||
|
|
||||||
|
public class DeploySmartContractTransaction<T extends Contract> implements Transaction<T> { |
||||||
|
|
||||||
|
private static final BigInteger DEFAULT_GAS_PRICE = BigInteger.valueOf(1000); |
||||||
|
private static final BigInteger DEFAULT_GAS_LIMIT = BigInteger.valueOf(3000000); |
||||||
|
private static final Credentials GENESIS_ACCOUNT_ONE_PRIVATE_KEY = |
||||||
|
Credentials.create("0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"); |
||||||
|
private static final Object METHOD_IS_STATIC = null; |
||||||
|
|
||||||
|
private final Class<T> clazz; |
||||||
|
|
||||||
|
public DeploySmartContractTransaction(final Class<T> clazz) { |
||||||
|
this.clazz = clazz; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public T execute(final Web3j node) { |
||||||
|
try { |
||||||
|
final Method method = |
||||||
|
clazz.getMethod( |
||||||
|
"deploy", Web3j.class, Credentials.class, BigInteger.class, BigInteger.class); |
||||||
|
|
||||||
|
final Object invoked = |
||||||
|
method.invoke( |
||||||
|
METHOD_IS_STATIC, |
||||||
|
node, |
||||||
|
GENESIS_ACCOUNT_ONE_PRIVATE_KEY, |
||||||
|
DEFAULT_GAS_PRICE, |
||||||
|
DEFAULT_GAS_LIMIT); |
||||||
|
|
||||||
|
return cast(invoked).send(); |
||||||
|
} catch (final Exception e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
private RemoteCall<T> cast(final Object invokedMethod) { |
||||||
|
return (RemoteCall<T>) invokedMethod; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue