Search in sources :

Example 1 with DataWord

use of org.aion.precompiled.util.DataWord 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 (byte[] k : members) {
        encodingList.add(new AddressFVM(k));
    }
    byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
    assertEquals(result.getStatus(), TransactionStatus.successful());
    // 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());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AddressFVM(org.aion.precompiled.encoding.AddressFVM) AbiEncoder(org.aion.precompiled.encoding.AbiEncoder) BigInteger(java.math.BigInteger) DataWord(org.aion.precompiled.util.DataWord) ListFVM(org.aion.precompiled.encoding.ListFVM) Test(org.junit.Test)

Example 2 with DataWord

use of org.aion.precompiled.util.DataWord in project aion by aionnetwork.

the class TotalCurrencyContractTest method constructUpdateInput.

/**
 * Constructs the input for an update request on the TotalCurrencyContract using AMT as the
 * value to update by and signs it using ownerKey.
 *
 * @param chainID The chain to update.
 * @param signum 0 for addition, 1 for subtraction.
 * @return the input byte array.
 */
private byte[] constructUpdateInput(byte chainID, byte signum) {
    ByteBuffer buffer = ByteBuffer.allocate(18);
    buffer.put(chainID).put(signum).put(new DataWord(AMT.toByteArray()).getData());
    byte[] payload = buffer.array();
    buffer = ByteBuffer.allocate(18 + 96);
    return buffer.put(payload).put(capabilities.sign(ownerAddr, Arrays.copyOf(payload, 32))).array();
}
Also used : DataWord(org.aion.precompiled.util.DataWord) ByteBuffer(java.nio.ByteBuffer)

Example 3 with DataWord

use of org.aion.precompiled.util.DataWord in project aion by aionnetwork.

the class TokenBridgeContractTest method testMinThreshold.

@Test
public void testMinThreshold() {
    // 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 (byte[] k : members) {
        encodingList.add(new AddressFVM(k));
    }
    byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
    assertEquals(result.getStatus(), TransactionStatus.successful());
    // try before
    byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
    assertTrue(transferResult.getStatus().isSuccess());
    assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("3")).getData());
    // explicitly set the min threshold to 5
    this.connector.setMinThresh(5);
    // try after
    byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
    assertTrue(transferResult2.getStatus().isSuccess());
    assertThat(transferResult2.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
    // try setting threshold greater than number of validator members
    this.connector.setMinThresh(10);
    // try after
    byte[] callPayload3 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult transferResult3 = this.contract.execute(callPayload3, DEFAULT_NRG);
    assertTrue(transferResult3.getStatus().isSuccess());
    assertThat(transferResult3.getReturnData()).isEqualTo(new DataWord(new BigInteger("10")).getData());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AddressFVM(org.aion.precompiled.encoding.AddressFVM) AbiEncoder(org.aion.precompiled.encoding.AbiEncoder) BigInteger(java.math.BigInteger) DataWord(org.aion.precompiled.util.DataWord) ListFVM(org.aion.precompiled.encoding.ListFVM) Test(org.junit.Test)

Aggregations

DataWord (org.aion.precompiled.util.DataWord)3 BigInteger (java.math.BigInteger)2 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)2 AbiEncoder (org.aion.precompiled.encoding.AbiEncoder)2 AddressFVM (org.aion.precompiled.encoding.AddressFVM)2 ListFVM (org.aion.precompiled.encoding.ListFVM)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1