Search in sources :

Example 1 with ErrCode

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

the class BridgeControllerOwnerTest method testInvalidOwnerTransferOwnership.

@Test
public void testInvalidOwnerTransferOwnership() {
    byte[] notOwner = HashUtil.h256("not owner".getBytes());
    byte[] newOwner = HashUtil.h256("newOwner".getBytes());
    this.controller.initialize();
    ErrCode err = this.controller.setNewOwner(notOwner, newOwner);
    assertThat(err).isEqualTo(ErrCode.NOT_OWNER);
}
Also used : ErrCode(org.aion.precompiled.contracts.ATB.ErrCode) Test(org.junit.Test)

Example 2 with ErrCode

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

the class BridgeControllerOwnerTest method testTransferOwnership.

@Test
public void testTransferOwnership() {
    byte[] transferOwnership = HashUtil.keccak256("ChangedOwner(address)".getBytes());
    byte[] newOwner = HashUtil.h256("newOwner".getBytes());
    this.controller.initialize();
    this.controller.setNewOwner(OWNER_ADDR.toByteArray(), newOwner);
    // sanity check
    assertThat(this.connector.getNewOwner()).isEqualTo(newOwner);
    ErrCode err = this.controller.acceptOwnership(newOwner);
    assertThat(err).isEqualTo(ErrCode.NO_ERROR);
    assertThat(this.connector.getOwner()).isEqualTo(newOwner);
    // check that an event was properly generated
    assertThat(this.logs.size()).isEqualTo(1);
    Log changedOwnerLog = this.logs.get(0);
    assertThat(changedOwnerLog.copyOfData()).isEqualTo(ByteUtil.EMPTY_BYTE_ARRAY);
    assertThat(changedOwnerLog.copyOfTopics().get(0)).isEqualTo(transferOwnership);
    assertThat(changedOwnerLog.copyOfTopics().get(1)).isEqualTo(newOwner);
}
Also used : Log(org.aion.types.Log) ErrCode(org.aion.precompiled.contracts.ATB.ErrCode) Test(org.junit.Test)

Example 3 with ErrCode

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

the class BridgeTransferTest method testBridgeTransferOne.

@Test
public void testBridgeTransferOne() {
    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("aionTransactionHash".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[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, new BridgeTransfer[] { bundle }, signatures);
    assertThat(results).isNotNull();
    assertThat(results.controllerResult).isEqualTo(ErrCode.NO_ERROR);
    assertThat(state.getBalance(CONTRACT_ADDR)).isEqualTo(BigInteger.ZERO);
}
Also used : 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 4 with ErrCode

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

the class BridgeTransferTest method testBeyondUpperBoundSignatures.

@Test
public void testBeyondUpperBoundSignatures() {
    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());
    // 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[6][];
    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_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 5 with ErrCode

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

the class BridgeTransferTest method testLowerBoundSignature.

@Test
public void testLowerBoundSignature() {
    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());
    // 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[3][];
    for (int i = 0; i < 3; 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.NO_ERROR);
    assertThat(state.getBalance(CONTRACT_ADDR)).isEqualTo(BigInteger.ZERO);
    assertThat(state.getBalance(new AionAddress(recipient))).isEqualTo(BigInteger.ONE);
}
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)

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