use of org.aion.types.AionAddress in project aion by aionnetwork.
the class TokenBridgeContractTest method setupForTest.
private ReturnDataFromSetup setupForTest(BridgeTransfer[] transfers, ECKey[] members) {
// override defaults
PrecompiledTransactionContext initializationContext = context(OWNER_ADDR, CONTRACT_ADDR);
this.contract = new TokenBridgeContract(initializationContext, ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
ListFVM encodingList = new ListFVM();
for (ECKey k : members) {
encodingList.add(new AddressFVM(k.getAddress()));
}
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertTrue(result.getStatus().isSuccess());
// set relayer
byte[] callPayload = new AbiEncoder(BridgeFuncSig.SIG_SET_RELAYER.getSignature(), new AddressFVM(members[0].getAddress())).encodeBytes();
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
// override defaults
this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN);
// we create a new token bridge contract here because we
// need to change the execution context
PrecompiledTransactionContext submitBundleContext = context(new AionAddress(members[0].getAddress()), CONTRACT_ADDR);
this.contract = new TokenBridgeContract(submitBundleContext, ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
// assemble the payload
byte[] blockHash = HashUtil.h256("blockHash".getBytes());
byte[] payloadHash = BridgeUtilities.computeBundleHash(blockHash, transfers);
byte[][] signatures = new byte[members.length][];
int i = 0;
for (ECKey k : members) {
signatures[i] = k.sign(payloadHash).toBytes();
i++;
}
ListFVM sourceTransactionList = new ListFVM();
ListFVM addressList = new ListFVM();
ListFVM uintList = new ListFVM();
for (BridgeTransfer b : transfers) {
sourceTransactionList.add(new AddressFVM(b.getSourceTransactionHash()));
addressList.add(new AddressFVM(b.getRecipient()));
uintList.add(new Uint128FVM(PrecompiledUtilities.pad(b.getTransferValue().toByteArray(), 16)));
}
ListFVM sigChunk1 = new ListFVM();
ListFVM sigChunk2 = new ListFVM();
ListFVM sigChunk3 = new ListFVM();
for (byte[] sig : signatures) {
sigChunk1.add(new AddressFVM(Arrays.copyOfRange(sig, 0, 32)));
sigChunk2.add(new AddressFVM(Arrays.copyOfRange(sig, 32, 64)));
sigChunk3.add(new AddressFVM(Arrays.copyOfRange(sig, 64, 96)));
}
callPayload = new AbiEncoder(BridgeFuncSig.SIG_SUBMIT_BUNDLE.getSignature(), new AddressFVM(blockHash), sourceTransactionList, addressList, uintList, sigChunk1, sigChunk2, sigChunk3).encodeBytes();
return new ReturnDataFromSetup(submitBundleContext, blockHash, payloadHash, callPayload);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionTransactionTest method testBeaconHashAbsent.
@Test
public void testBeaconHashAbsent() {
byte[] nonce = RandomUtils.nextBytes(16);
AionAddress to = new AionAddress(RandomUtils.nextBytes(32));
byte[] value = RandomUtils.nextBytes(16);
byte[] data = RandomUtils.nextBytes(64);
long nrg = 0;
long nrgPrice = 0;
byte type = 0;
AionTransaction tx = AionTransaction.create(key, nonce, to, value, data, nrg, nrgPrice, type, null);
assertNull("beacon hash should be null", tx.getBeaconHash());
SharedRLPList decoded = (SharedRLPList) RLP.decode2SharedList(tx.getEncoded()).get(0);
assertEquals("wrong number of elements in RLP encoding of AionTransaction without beacon hash", TxUtil.RLP_TX_SIG, decoded.size() - 1);
AionTransaction tx2 = TxUtil.decodeUsingRlpSharedList(tx.getEncoded());
assertNotNull(tx2);
assertTransactionEquals(tx, tx2);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class TXValidatorTest method validateTxSignatureSwapForkEnabledReceiverAddressTest.
@Test
public void validateTxSignatureSwapForkEnabledReceiverAddressTest() {
boolean signatureSwapEnabled = true;
byte[] dest = RandomUtils.nextBytes(32);
dest[0] = (byte) 0xa1;
AionTransaction tx = AionTransaction.create(key, nonce, new AionAddress(dest), value, data, nrg, nrgPrice, type, null);
TxResponse response = TXValidator.validateTx(tx, unityForkEnabled, signatureSwapEnabled);
assertEquals(TxResponse.INVALID_TX_DESTINATION, response);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class InvokableTransactionTest method encodeDecodeTest.
@Test
public void encodeDecodeTest() {
Transaction tx = Transaction.contractCallTransaction(new AionAddress(key.getAddress()), AddressUtils.ZERO_ADDRESS, new byte[0], BigInteger.ZERO, BigInteger.ZERO, new byte[0], 1L, 1L);
AionAddress executor = AddressUtils.ZERO_ADDRESS;
byte[] invokable = InvokableTxUtil.encodeInvokableTransaction(key, tx.nonce, tx.destinationAddress, tx.value, tx.copyOfTransactionData(), executor);
InternalTransaction tx2 = InvokableTxUtil.decode(invokable, AddressUtils.ZERO_ADDRESS, 21000, 1);
assertNotNull(tx2);
assertEquals(tx.destinationAddress, tx2.destination);
assertEquals(tx.nonce, tx2.senderNonce);
assertEquals(tx.value, tx2.value);
assertArrayEquals(tx.copyOfTransactionData(), tx2.copyOfData());
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class InvokableTransactionTest method nullExecutorTest.
@Test
public void nullExecutorTest() {
Transaction tx = Transaction.contractCallTransaction(new AionAddress(key.getAddress()), AddressUtils.ZERO_ADDRESS, new byte[0], BigInteger.ZERO, BigInteger.ZERO, new byte[0], 1L, 1L);
byte[] invokable = InvokableTxUtil.encodeInvokableTransaction(key, tx.nonce, tx.destinationAddress, tx.value, tx.copyOfTransactionData(), null);
InternalTransaction tx2 = InvokableTxUtil.decode(invokable, getRandomAddress(), 21000, 1);
assertNotNull(tx2);
assertEquals(tx.destinationAddress, tx2.destination);
assertEquals(tx.nonce, tx2.senderNonce);
assertEquals(tx.value, tx2.value);
assertArrayEquals(tx.copyOfTransactionData(), tx2.copyOfData());
}
Aggregations