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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations