Search in sources :

Example 71 with AionAddress

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);
}
Also used : Uint128FVM(org.aion.zero.impl.precompiled.encoding.Uint128FVM) AionAddress(org.aion.types.AionAddress) TokenBridgeContract(org.aion.precompiled.contracts.ATB.TokenBridgeContract) AddressFVM(org.aion.zero.impl.precompiled.encoding.AddressFVM) AbiEncoder(org.aion.zero.impl.precompiled.encoding.AbiEncoder) ECKey(org.aion.crypto.ECKey) BridgeTransfer(org.aion.precompiled.contracts.ATB.BridgeTransfer) ListFVM(org.aion.zero.impl.precompiled.encoding.ListFVM) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext)

Example 72 with AionAddress

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);
}
Also used : AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) SharedRLPList(org.aion.rlp.SharedRLPList) Test(org.junit.Test)

Example 73 with AionAddress

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);
}
Also used : AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) TxResponse(org.aion.zero.impl.types.TxResponse) Test(org.junit.Test)

Example 74 with AionAddress

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());
}
Also used : AionAddress(org.aion.types.AionAddress) InternalTransaction(org.aion.types.InternalTransaction) Transaction(org.aion.types.Transaction) InternalTransaction(org.aion.types.InternalTransaction) Test(org.junit.Test)

Example 75 with AionAddress

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());
}
Also used : AionAddress(org.aion.types.AionAddress) InternalTransaction(org.aion.types.InternalTransaction) Transaction(org.aion.types.Transaction) InternalTransaction(org.aion.types.InternalTransaction) Test(org.junit.Test)

Aggregations

AionAddress (org.aion.types.AionAddress)491 Test (org.junit.Test)364 AionTransaction (org.aion.base.AionTransaction)275 BigInteger (java.math.BigInteger)194 ImportResult (org.aion.zero.impl.core.ImportResult)110 AionTxExecSummary (org.aion.base.AionTxExecSummary)97 RepositoryCache (org.aion.base.db.RepositoryCache)90 MiningBlock (org.aion.zero.impl.types.MiningBlock)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)80 ArrayList (java.util.ArrayList)76 ECKey (org.aion.crypto.ECKey)74 AionTxReceipt (org.aion.base.AionTxReceipt)60 Block (org.aion.zero.impl.types.Block)60 AccountState (org.aion.base.AccountState)56 HashMap (java.util.HashMap)42 DataWord (org.aion.util.types.DataWord)39 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)36 InternalTransaction (org.aion.types.InternalTransaction)32 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)29 BlockContext (org.aion.zero.impl.types.BlockContext)29