use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TokenBridgeContractTest method testRemoveRingMember.
@Test
public void testRemoveRingMember() {
// override defaults
this.contract = new TokenBridgeContract(context(OWNER_ADDR, CONTRACT_ADDR), 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()));
}
// address null - fail
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_REMOVE_MEMBER.getSignature()).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertEquals("FAILURE", result.getStatus().causeOfError);
// add new member - fail
byte[] sig = new AbiEncoder(BridgeFuncSig.SIG_RING_REMOVE_MEMBER.getSignature(), encodingList).encodeBytes();
// the new member
byte[] newMember = ECKeyFac.inst().create().getAddress();
byte[] payload2 = new byte[4 + 32];
System.arraycopy(sig, 0, payload2, 0, 4);
System.arraycopy(newMember, 0, payload2, 4, 32);
PrecompiledTransactionResult result2 = this.contract.execute(payload2, DEFAULT_NRG);
assertEquals("FAILURE", result2.getStatus().causeOfError);
// initialize ring
byte[] ring = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
this.contract.execute(ring, DEFAULT_NRG);
// remove member - fail, member does not exist
byte[] sig3 = new AbiEncoder(BridgeFuncSig.SIG_RING_REMOVE_MEMBER.getSignature(), encodingList).encodeBytes();
// the new member
byte[] newMember3 = ECKeyFac.inst().create().getAddress();
byte[] payload3 = new byte[4 + 32];
System.arraycopy(sig3, 0, payload3, 0, 4);
System.arraycopy(newMember3, 0, payload3, 4, 32);
PrecompiledTransactionResult result3 = this.contract.execute(payload3, DEFAULT_NRG);
assertEquals("FAILURE", result3.getStatus().causeOfError);
// remove member - success, member exists
byte[] sig4 = new AbiEncoder(BridgeFuncSig.SIG_RING_REMOVE_MEMBER.getSignature(), encodingList).encodeBytes();
byte[] payload4 = new byte[4 + 32];
System.arraycopy(sig4, 0, payload4, 0, 4);
System.arraycopy(members[0].getAddress(), 0, payload4, 4, 32);
PrecompiledTransactionResult result4 = this.contract.execute(payload4, DEFAULT_NRG);
assertTrue(result4.getStatus().isSuccess());
}
use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TotalCurrencyContractTest method TestGetTotalInsufficientNrg.
@Test
public void TestGetTotalInsufficientNrg() {
System.out.println("Running TestUpdateTotalInsufficientNrg.");
PrecompiledTransactionResult res = tcc.execute(new byte[] { (byte) 0x0 }, COST - 1);
assertEquals("OUT_OF_NRG", res.getStatus().causeOfError);
assertEquals(0L, res.getEnergyRemaining());
}
use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TotalCurrencyContractTest method TestUpdateTotalIncorrectSigSize.
@Test
public void TestUpdateTotalIncorrectSigSize() {
System.out.println("Running TestUpdateTotalIncorrectSigSize.");
byte[] input = Arrays.copyOfRange(constructUpdateInput((byte) 0x0, (byte) 0x0), 0, // cut sig short.
100);
PrecompiledTransactionResult res = tcc.execute(input, COST);
assertEquals("FAILURE", res.getStatus().causeOfError);
assertEquals(0L, res.getEnergyRemaining());
}
use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TotalCurrencyContractTest method TestUpdateTotalNotOwner.
@Test
public void TestUpdateTotalNotOwner() {
System.out.println("Running TestUpdateTotalNotOwner.");
TotalCurrencyContract contract = new TotalCurrencyContract(state, ADDR, // diff owner.
new AionAddress(ECKeyFac.inst().create().getAddress()));
byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0);
PrecompiledTransactionResult res = contract.execute(input, COST);
assertEquals("FAILURE", res.getStatus().causeOfError);
assertEquals(0L, res.getEnergyRemaining());
}
use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TotalCurrencyContractTest method TestUpdateAndGetDiffChainIds.
@Test
public void TestUpdateAndGetDiffChainIds() {
System.out.println("Running TestUpdateAndGetDiffChainIds.");
byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0);
PrecompiledTransactionResult res = tcc.execute(input, COST);
assertTrue(res.getStatus().isSuccess());
assertEquals(0L, res.getEnergyRemaining());
// query a diff chainID
res = tcc.execute(new byte[] { (byte) 0x1 }, COST);
assertTrue(res.getStatus().isSuccess());
assertEquals(BigInteger.ZERO, new BigInteger(1, res.getReturnData()));
}
Aggregations