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