use of org.aion.zero.impl.precompiled.encoding.ListFVM in project aion by aionnetwork.
the class TokenBridgeContractTest method testMemberCount.
@Test
public void testMemberCount() {
// 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()));
}
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertTrue(result.getStatus().isSuccess());
// try before
byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
// explicitly set the member count to 10
this.connector.setMemberCount(10);
// try after
byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
assertTrue(transferResult2.getStatus().isSuccess());
assertThat(transferResult2.getReturnData()).isEqualTo(new DataWord(new BigInteger("10")).getData());
}
use of org.aion.zero.impl.precompiled.encoding.ListFVM in project aion by aionnetwork.
the class TokenBridgeContractTest method testRingMap.
@Test
public void testRingMap() {
// 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()));
}
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertTrue(result.getStatus().isSuccess());
// create input byte[]
byte[] callPayload = new byte[36];
byte[] encodeBytes = new AbiEncoder(BridgeFuncSig.PURE_RING_MAP.getSignature()).encodeBytes();
ECKey newKey = ECKeyFac.inst().create();
byte[] randomAddress = newKey.getAddress();
System.arraycopy(encodeBytes, 0, callPayload, 0, 4);
System.arraycopy(randomAddress, 0, callPayload, 4, 32);
// execute with valid input
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
// execute with invalid input
PrecompiledTransactionResult transferResult2 = this.contract.execute(encodeBytes, DEFAULT_NRG);
assertEquals("FAILURE", transferResult2.getStatus().causeOfError);
}
use of org.aion.zero.impl.precompiled.encoding.ListFVM in project aion by aionnetwork.
the class TokenBridgeContractTest method testRemoveRingMemberNotOwner.
@Test
public void testRemoveRingMemberNotOwner() {
// 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);
// override defaults
this.contract = new TokenBridgeContract(context(AddressUtils.ZERO_ADDRESS, CONTRACT_ADDR), ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
// failure, member exists but sender is no longer owner
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);
assertEquals("FAILURE", result4.getStatus().causeOfError);
}
Aggregations