Search in sources :

Example 6 with Request

use of org.aion.rpc.types.RPCTypes.Request in project aion by aionnetwork.

the class PersonalRPCImplTest method testPersonal_ListAccounts.

@Test
public void testPersonal_ListAccounts() {
    List<AionAddress> address = new ArrayList<>();
    AccountManager accountManager = new AccountManager(AionLoggerFactory.getLogger(LogEnum.API.name()));
    int addressCount = 3;
    for (int i = 0; i < addressCount; i++) {
        address.add(accountManager.createAccount("password"));
    }
    chainHolder = spy(new AionChainHolder(AionImpl.instForTest(), accountManager));
    doCallRealMethod().when(chainHolder).listAccounts();
    rpc = spy(new RPCMethods(chainHolder));
    doCallRealMethod().when(rpc).personal_listAccounts();
    Request request = new Request(idGenerator.generateID(), listAccountMethod, null, VersionType.Version2);
    List<AionAddress> aionAddressList = execute(request, AddressListConverter::decode);
    verify(chainHolder, atLeastOnce()).listAccounts();
    assertEquals(addressCount, aionAddressList.size());
    // check that we get all
    assertEquals(Set.copyOf(address), Set.copyOf(aionAddressList));
// the expected addresses
}
Also used : AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) Request(org.aion.rpc.types.RPCTypes.Request) AccountManager(org.aion.api.server.account.AccountManager) AddressListConverter(org.aion.rpc.types.RPCTypesConverter.AddressListConverter) Test(org.junit.Test)

Example 7 with Request

use of org.aion.rpc.types.RPCTypes.Request in project aion by aionnetwork.

the class StakingRPCImplTest method testCallUnityFeatureBeforeFork.

@Test
public void testCallUnityFeatureBeforeFork() {
    chainHolder = spy(new AionChainHolder(AionImpl.instForTest(), accountManager));
    doReturn(false).when(chainHolder).isUnityForkEnabled();
    doCallRealMethod().when(chainHolder).getSeed();
    rpcMethods = new RPCMethods(chainHolder);
    try {
        // This call will throw because a unity feature is requested before
        // The unity fork
        execute(new Request(1, "getseed", VoidParamsConverter.encode(new VoidParams()), VersionType.Version2), RPCTypesConverter.ByteArrayConverter::decode);
        fail();
    } catch (UnsupportedUnityFeatureRPCException e) {
    // pass
    }
}
Also used : UnsupportedUnityFeatureRPCException(org.aion.rpc.errors.RPCExceptions.UnsupportedUnityFeatureRPCException) Request(org.aion.rpc.types.RPCTypes.Request) VoidParams(org.aion.rpc.types.RPCTypes.VoidParams) Test(org.junit.Test)

Example 8 with Request

use of org.aion.rpc.types.RPCTypes.Request in project aion by aionnetwork.

the class OpsRPCImplTest method testOps_getTransaction.

@Test
public void testOps_getTransaction() {
    Request request = new Request(idGenerator.generateID(), getTransactionMethod, TransactionHashParamsConverter.encode(new TransactionHashParams(transactionHash)), VersionType.Version2);
    assertNotNull(execute(request, OpsTransactionConverter::decode));
}
Also used : Request(org.aion.rpc.types.RPCTypes.Request) TransactionHashParams(org.aion.rpc.types.RPCTypes.TransactionHashParams) Test(org.junit.Test)

Example 9 with Request

use of org.aion.rpc.types.RPCTypes.Request in project aion by aionnetwork.

the class OpsRPCImplTest method testOps_getAccountState.

@Test
public void testOps_getAccountState() {
    AionAddress aionAddress = new AionAddress(ByteUtil.hexStringToBytes("a07913c03686c9659c1b614d098fd1db380a52b71fd58526b53d8107f7b355d5"));
    Request request = new Request(idGenerator.generateID(), getAccountStateMethod, AddressParamsConverter.encode(new AddressParams(aionAddress)), VersionType.Version2);
    final RPCTypes.AccountState result = execute(request, AccountStateConverter::decode);
    assertNotNull(result);
    assertEquals(aionAddress, result.address);
    assertEquals(BigInteger.TEN, result.balance);
    assertEquals(BigInteger.TEN, result.nonce);
}
Also used : AionAddress(org.aion.types.AionAddress) AccountStateConverter(org.aion.rpc.types.RPCTypesConverter.AccountStateConverter) Request(org.aion.rpc.types.RPCTypes.Request) RPCTypes(org.aion.rpc.types.RPCTypes) AddressParams(org.aion.rpc.types.RPCTypes.AddressParams) Test(org.junit.Test)

Example 10 with Request

use of org.aion.rpc.types.RPCTypes.Request in project aion by aionnetwork.

the class OpsRPCImplTest method testOps_getBlockDetails.

@Test
public void testOps_getBlockDetails() {
    assertNotNull(execute(new Request(idGenerator.generateID(), "ops_getBlockDetails", BlockSpecifierParamsConverter.encode(new BlockSpecifierParams(new BlockSpecifierUnion(1L))), VersionType.Version2), BlockDetailsConverter::decode));
    assertNotNull(execute(new Request(idGenerator.generateID(), "ops_getBlockDetails", BlockSpecifierParamsConverter.encode(BlockSpecifierParamsConverter.decode("[latest]")), VersionType.Version2), BlockDetailsConverter::decode));
    assertNotNull(execute(new Request(idGenerator.generateID(), "ops_getBlockDetails", BlockSpecifierParamsConverter.encode(BlockSpecifierParamsConverter.decode("{\"block\": \"" + ByteArray.wrap(emptyPowBlock.getHash()) + "\"}")), VersionType.Version2), BlockDetailsConverter::decode));
}
Also used : BlockSpecifierUnion(org.aion.rpc.types.RPCTypes.BlockSpecifierUnion) BlockSpecifierParams(org.aion.rpc.types.RPCTypes.BlockSpecifierParams) Request(org.aion.rpc.types.RPCTypes.Request) Test(org.junit.Test)

Aggregations

Request (org.aion.rpc.types.RPCTypes.Request)16 Test (org.junit.Test)15 AionAddress (org.aion.types.AionAddress)5 VoidParams (org.aion.rpc.types.RPCTypes.VoidParams)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SubmissionResult (org.aion.rpc.types.RPCTypes.SubmissionResult)2 SubmitBlockParams (org.aion.rpc.types.RPCTypes.SubmitBlockParams)2 SubmitSignatureParams (org.aion.rpc.types.RPCTypes.SubmitSignatureParams)2 AddressConverter (org.aion.rpc.types.RPCTypesConverter.AddressConverter)2 SubmissionResultConverter (org.aion.rpc.types.RPCTypesConverter.SubmissionResultConverter)2 AionBlockchainImpl (org.aion.zero.impl.blockchain.AionBlockchainImpl)2 AionImpl (org.aion.zero.impl.blockchain.AionImpl)2 Stopwatch (com.google.common.base.Stopwatch)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 AccountManager (org.aion.api.server.account.AccountManager)1 ECKey (org.aion.crypto.ECKey)1 RPCExceptions (org.aion.rpc.errors.RPCExceptions)1 BlockTemplateNotFoundRPCException (org.aion.rpc.errors.RPCExceptions.BlockTemplateNotFoundRPCException)1 InternalErrorRPCException (org.aion.rpc.errors.RPCExceptions.InternalErrorRPCException)1