Package org.aion.avm.embed
Class AvmRule
- java.lang.Object
-
- org.aion.avm.embed.AvmRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public final class AvmRule extends java.lang.Object implements org.junit.rules.TestRule
TestRule to handle the boilerplate operations of testing with an embedded avm.If declared with @Rule annotation, the kernel and avm are instantiated for each for each test.
Otherwise, when declared with @ClassRule annotation, the kernel and avm are instantiated once for the test class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AvmRule.ResultWrapper
An abstract container of the result of running a transaction or call onAvmRule
.
-
Constructor Summary
Constructors Constructor Description AvmRule(boolean debugMode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement statement, org.junit.runner.Description description)
AvmRule.ResultWrapper
balanceTransfer(Address from, Address to, java.math.BigInteger value, long energyLimit, long energyPrice)
Makes a balance transfer.AvmRule.ResultWrapper
call(Address from, Address dappAddress, java.math.BigInteger value, byte[] transactionData)
Makes a call transaction to the Dapp.AvmRule.ResultWrapper
call(Address from, Address dappAddress, java.math.BigInteger value, byte[] transactionData, long energyLimit, long energyPrice)
Makes a call transaction to the Dapp.AvmRule.ResultWrapper
deploy(Address from, java.math.BigInteger value, byte[] dappBytes)
Deploys the Dapp.AvmRule.ResultWrapper
deploy(Address from, java.math.BigInteger value, byte[] dappBytes, long energyLimit, long energyPrice)
Deploys the Dapp.void
disableAutomaticBlockGeneration()
Disables automatic generation of blocks for each transactionbyte[]
getDappBytes(java.lang.Class<?> mainClass, byte[] arguments, int abiVersion, java.lang.Class<?>... otherClasses)
Retrieves bytes corresponding to the in-memory representation of Dapp jar.byte[]
getDappBytes(java.lang.Class<?> mainClass, byte[] arguments, java.lang.Class<?>... otherClasses)
Retrieves bytes corresponding to the in-memory representation of Dapp jar.byte[]
getDappBytesWithoutOptimization(java.lang.Class<?> mainClass, byte[] arguments, java.lang.Class<?>... otherClasses)
Retrieves bytes corresponding to the in-memory representation of Dapp jar.Address
getPreminedAccount()
Address
getRandomAddress(java.math.BigInteger initialBalance)
Creates an account with an initial balance in the kernel
-
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runner.Description description)
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
getDappBytes
public byte[] getDappBytes(java.lang.Class<?> mainClass, byte[] arguments, java.lang.Class<?>... otherClasses)
Retrieves bytes corresponding to the in-memory representation of Dapp jar. This uses the base ABI compiler version.- Parameters:
mainClass
- Main class of the Dapp to include and list in manifest (can be null).arguments
- Constructor argumentsotherClasses
- Other classes to include (main is already included).- Returns:
- Byte array corresponding to the optimized deployable Dapp jar and arguments, where unreachable classes and methods are removed from the jar
-
getDappBytes
public byte[] getDappBytes(java.lang.Class<?> mainClass, byte[] arguments, int abiVersion, java.lang.Class<?>... otherClasses)
Retrieves bytes corresponding to the in-memory representation of Dapp jar.- Parameters:
mainClass
- Main class of the Dapp to include and list in manifest (can be null).arguments
- Constructor argumentsabiVersion
- Version of ABI compiler to useotherClasses
- Other classes to include (main is already included).- Returns:
- Byte array corresponding to the optimized deployable Dapp jar and arguments, where unreachable classes and methods are removed from the jar
-
getDappBytesWithoutOptimization
public byte[] getDappBytesWithoutOptimization(java.lang.Class<?> mainClass, byte[] arguments, java.lang.Class<?>... otherClasses)
Retrieves bytes corresponding to the in-memory representation of Dapp jar. This is always using the latest ABI version.- Parameters:
mainClass
- Main class of the Dapp to include and list in manifest (can be null).arguments
- Constructor argumentsotherClasses
- Other classes to include (main is already included).- Returns:
- Byte array corresponding to the deployable Dapp jar and arguments.
-
deploy
public AvmRule.ResultWrapper deploy(Address from, java.math.BigInteger value, byte[] dappBytes, long energyLimit, long energyPrice)
Deploys the Dapp.- Parameters:
from
- Address of the deployer accountvalue
- Value to transfer to the DappdappBytes
- Byte array corresponding to the Dapp jarenergyLimit
- Maximum energy to be used for deploymentenergyPrice
- Energy price to be used for deployment- Returns:
- Result of the operation
-
deploy
public AvmRule.ResultWrapper deploy(Address from, java.math.BigInteger value, byte[] dappBytes)
Deploys the Dapp. Energy limit is set to the maximum allowed in the kernel for deploying contracts- Parameters:
from
- Address of the deployer accountvalue
- Value to transfer to the DappdappBytes
- Byte array corresponding to the Dapp jar- Returns:
- Result of the operation
-
call
public AvmRule.ResultWrapper call(Address from, Address dappAddress, java.math.BigInteger value, byte[] transactionData, long energyLimit, long energyPrice)
Makes a call transaction to the Dapp.- Parameters:
from
- Address of the account calling the DappdappAddress
- Address of the Dappvalue
- Value to transfer with the calltransactionData
- The encoded byte array that contains the method descriptor, argument descriptor and encoded arguments, according the Aion ABI format.energyLimit
- Maximum energy to be used for the callenergyPrice
- Energy price to be used for the call- Returns:
- Result of the operation
-
call
public AvmRule.ResultWrapper call(Address from, Address dappAddress, java.math.BigInteger value, byte[] transactionData)
Makes a call transaction to the Dapp. Energy limit is set to the maximum allowed in the kernel for a call transaction- Parameters:
from
- Address of the account calling the DappdappAddress
- Address of the Dappvalue
- Value to transfer with the calltransactionData
- The encoded byte array that contains the method descriptor, argument descriptor and encoded arguments, according the Aion ABI format.- Returns:
- Result of the operation
-
balanceTransfer
public AvmRule.ResultWrapper balanceTransfer(Address from, Address to, java.math.BigInteger value, long energyLimit, long energyPrice)
Makes a balance transfer.- Parameters:
from
- Address of senderto
- Address of the receivervalue
- Transfer amountenergyLimit
- Maximum energy to be used for the callenergyPrice
- Energy price to be used for the transfer- Returns:
- Result of the operation
-
getRandomAddress
public Address getRandomAddress(java.math.BigInteger initialBalance)
Creates an account with an initial balance in the kernel- Parameters:
initialBalance
- Initial balance of the created account- Returns:
- Address of the newly created account
-
getPreminedAccount
public Address getPreminedAccount()
- Returns:
- Address of the account with initial (pre-mined) balance in the kernel
-
disableAutomaticBlockGeneration
public void disableAutomaticBlockGeneration()
Disables automatic generation of blocks for each transaction
-
-