Search in sources :

Example 6 with ErrCode

use of org.aion.precompiled.contracts.ATB.ErrCode in project aion by aionnetwork.

the class BridgeTransferTest method testTransferZeroBundle.

@Test
public void testTransferZeroBundle() {
    final byte[] senderAddress = members[0].getAddress();
    final byte[] blockHash = HashUtil.h256("blockHash".getBytes());
    final byte[] recipient = HashUtil.h256("recipient".getBytes());
    final byte[] sourceTransactionHash = HashUtil.h256("transaction".getBytes());
    final byte[] aionTransactionHash = HashUtil.h256("aionTransaction".getBytes());
    state.addBalance(CONTRACT_ADDR, BigInteger.ONE);
    BridgeTransfer bundle = BridgeTransfer.getInstance(BigInteger.ZERO, recipient, sourceTransactionHash);
    byte[] bundleHash = BridgeUtilities.computeBundleHash(blockHash, new BridgeTransfer[] { bundle });
    byte[][] signatures = new byte[5][];
    for (int i = 0; i < 5; i++) {
        signatures[i] = members[i].sign(bundleHash).toBytes();
    }
    ErrCode code = this.controller.setRelayer(OWNER_ADDR.toByteArray(), senderAddress);
    assertThat(code).isEqualTo(ErrCode.NO_ERROR);
    BridgeController.ProcessedResults results = this.controller.processBundles(senderAddress, aionTransactionHash, blockHash, new BridgeTransfer[] { bundle }, signatures);
    assertThat(results).isNotNull();
    assertThat(results.controllerResult).isEqualTo(ErrCode.INVALID_TRANSFER);
    assertThat(state.getBalance(CONTRACT_ADDR)).isEqualTo(BigInteger.ONE);
    assertThat(state.getBalance(new AionAddress(recipient))).isEqualTo(BigInteger.ZERO);
}
Also used : AionAddress(org.aion.types.AionAddress) BridgeTransfer(org.aion.precompiled.contracts.ATB.BridgeTransfer) BridgeController(org.aion.precompiled.contracts.ATB.BridgeController) ErrCode(org.aion.precompiled.contracts.ATB.ErrCode) Test(org.junit.Test)

Example 7 with ErrCode

use of org.aion.precompiled.contracts.ATB.ErrCode in project aion by aionnetwork.

the class BridgeControllerRingTest method testRingRemoveMember.

@Test
public void testRingRemoveMember() {
    ErrCode code;
    code = this.controller.ringAddMember(OWNER_ADDR.toByteArray(), memberAddress);
    assertThat(code).isEqualTo(ErrCode.NO_ERROR);
    assertThat(this.connector.getActiveMember(memberAddress)).isTrue();
    code = this.controller.ringRemoveMember(OWNER_ADDR.toByteArray(), memberAddress);
    assertThat(code).isEqualTo(ErrCode.NO_ERROR);
    assertThat(this.connector.getActiveMember(memberAddress)).isFalse();
}
Also used : ErrCode(org.aion.precompiled.contracts.ATB.ErrCode) Test(org.junit.Test)

Example 8 with ErrCode

use of org.aion.precompiled.contracts.ATB.ErrCode in project aion by aionnetwork.

the class BridgeTransferTest method executeSignController.

private ResultHashTuple executeSignController(byte[] senderAddress, byte[] blockHash, byte[] aionTransactionHash, BridgeTransfer[] transfers) {
    resetContext();
    byte[] bundleHash = BridgeUtilities.computeBundleHash(blockHash, transfers);
    byte[][] signatures = new byte[members.length][];
    for (int i = 0; i < members.length; i++) {
        signatures[i] = members[i].sign(bundleHash).toBytes();
    }
    ErrCode code = this.controller.setRelayer(OWNER_ADDR.toByteArray(), senderAddress);
    assertThat(code).isEqualTo(ErrCode.NO_ERROR);
    BridgeController.ProcessedResults results = this.controller.processBundles(senderAddress, aionTransactionHash, blockHash, transfers, signatures);
    ResultHashTuple tuple = new ResultHashTuple();
    tuple.bundleHash = bundleHash;
    tuple.results = results;
    return tuple;
}
Also used : BridgeController(org.aion.precompiled.contracts.ATB.BridgeController) ErrCode(org.aion.precompiled.contracts.ATB.ErrCode)

Example 9 with ErrCode

use of org.aion.precompiled.contracts.ATB.ErrCode in project aion by aionnetwork.

the class BridgeTransferTest method testBridgeNotEnoughSignatures.

@Test
public void testBridgeNotEnoughSignatures() {
    final byte[] senderAddress = members[0].getAddress();
    final byte[] blockHash = HashUtil.h256("blockHash".getBytes());
    final byte[] recipient = HashUtil.h256("recipient".getBytes());
    final byte[] sourceTransactionHash = HashUtil.h256("transaction".getBytes());
    // ATB-4, this is the hash of the aion transaction which submitted
    // this bundle, this is different from the source transaction hash
    // which is transferred from another blockchain network.
    final byte[] aionTransactionHash = HashUtil.h256("aionTransaction".getBytes());
    // ensure we have enough balance
    state.addBalance(CONTRACT_ADDR, BigInteger.ONE);
    BridgeTransfer bundle = BridgeTransfer.getInstance(BigInteger.valueOf(1), recipient, sourceTransactionHash);
    byte[] bundleHash = BridgeUtilities.computeBundleHash(blockHash, new BridgeTransfer[] { bundle });
    byte[][] signatures = new byte[2][];
    for (int i = 0; i < 2; i++) {
        signatures[i] = members[i].sign(bundleHash).toBytes();
    }
    ErrCode code = this.controller.setRelayer(OWNER_ADDR.toByteArray(), senderAddress);
    assertThat(code).isEqualTo(ErrCode.NO_ERROR);
    BridgeController.ProcessedResults results = this.controller.processBundles(senderAddress, aionTransactionHash, blockHash, new BridgeTransfer[] { bundle }, signatures);
    assertThat(results).isNotNull();
    assertThat(results.controllerResult).isEqualTo(ErrCode.INVALID_SIGNATURE_BOUNDS);
    assertThat(state.getBalance(CONTRACT_ADDR)).isEqualTo(BigInteger.ONE);
    assertThat(state.getBalance(new AionAddress(recipient))).isEqualTo(BigInteger.ZERO);
}
Also used : AionAddress(org.aion.types.AionAddress) BridgeTransfer(org.aion.precompiled.contracts.ATB.BridgeTransfer) BridgeController(org.aion.precompiled.contracts.ATB.BridgeController) ErrCode(org.aion.precompiled.contracts.ATB.ErrCode) Test(org.junit.Test)

Example 10 with ErrCode

use of org.aion.precompiled.contracts.ATB.ErrCode in project aion by aionnetwork.

the class BridgeControllerRingTest method testRingAddExistingMember.

@Test
public void testRingAddExistingMember() {
    // add member twice
    this.controller.ringAddMember(OWNER_ADDR.toByteArray(), memberAddress);
    ErrCode code = this.controller.ringAddMember(OWNER_ADDR.toByteArray(), memberAddress);
    assertThat(code).isEqualTo(ErrCode.RING_MEMBER_EXISTS);
}
Also used : ErrCode(org.aion.precompiled.contracts.ATB.ErrCode) Test(org.junit.Test)

Aggregations

ErrCode (org.aion.precompiled.contracts.ATB.ErrCode)19 Test (org.junit.Test)18 BridgeController (org.aion.precompiled.contracts.ATB.BridgeController)6 BridgeTransfer (org.aion.precompiled.contracts.ATB.BridgeTransfer)5 AionAddress (org.aion.types.AionAddress)4 Log (org.aion.types.Log)1