Search in sources :

Example 1 with Request

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

the class MiningRPCImplTest method getWorkTest.

@Test
public void getWorkTest() {
    ChainHolder chainHolder = new AionChainHolder(AionImpl.instForTest(), accountManager);
    rpcMethods = new RPCMethods(chainHolder);
    final BlockTemplate blockTemplate = rpcMethods.getBlockTemplate();
    assertNotNull(blockTemplate);
    assertTrue(chainHolder.canSeal(blockTemplate.headerHash.toBytes()));
    BlockTemplateConverter.encode(blockTemplate);
    final Request request = buildRequest("getBlockTemplate", VoidParamsConverter.encode(new VoidParams()));
    BlockTemplateConverter.encode(execute(request, BlockTemplateConverter::decode));
}
Also used : Request(org.aion.rpc.types.RPCTypes.Request) VoidParams(org.aion.rpc.types.RPCTypes.VoidParams) BlockTemplate(org.aion.rpc.types.RPCTypes.BlockTemplate) Test(org.junit.Test)

Example 2 with Request

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

the class MiningRPCImplTest method getDifficulty.

@Test
public void getDifficulty() {
    ChainHolder chainHolder = new AionChainHolder(AionImpl.instForTest(), accountManager);
    rpcMethods = new RPCMethods(chainHolder);
    final BigInteger difficulty = rpcMethods.getDifficulty();
    assertNotNull(difficulty);
    final Request request = buildRequest("getDifficulty", VoidParamsConverter.encode(new VoidParams()));
    BigIntConverter.encode(execute(request, RPCTypesConverter.BigIntConverter::decode));
}
Also used : RPCTypesConverter(org.aion.rpc.types.RPCTypesConverter) Request(org.aion.rpc.types.RPCTypes.Request) VoidParams(org.aion.rpc.types.RPCTypes.VoidParams) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 3 with Request

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

the class PersonalRPCImplTest method testPersonal_lockAccount.

@Test
public void testPersonal_lockAccount() {
    AionAddress address = new AionAddress(ByteUtil.hexStringToBytes("a07913c03686c9659c1b614d098fd1db380a52b71fd58526b53d8107f7b355d5"));
    String password0 = "password";
    String password1 = "password1";
    LockAccountParams params0 = new LockAccountParams(address, password0);
    LockAccountParams params1 = new LockAccountParams(address, password1);
    doReturn(false).when(chainHolder).lockAccount(eq(address), eq(password0));
    doReturn(true).when(chainHolder).lockAccount(eq(address), eq(password1));
    assertFalse(execute(new Request(idGenerator.generateID(), lockAccountMethod, LockAccountParamsConverter.encode(params0), VersionType.Version2), BoolConverter::decode));
    assertTrue(execute(new Request(idGenerator.generateID(), lockAccountMethod, LockAccountParamsConverter.encode(params1), VersionType.Version2), BoolConverter::decode));
}
Also used : AionAddress(org.aion.types.AionAddress) Request(org.aion.rpc.types.RPCTypes.Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LockAccountParams(org.aion.rpc.types.RPCTypes.LockAccountParams) Test(org.junit.Test)

Example 4 with Request

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

the class PersonalRPCImplTest method executePersonal_ecRecover.

@Test
public void executePersonal_ecRecover() {
    ECKey ecKey = ECKeyFac.inst().create();
    String helloMessage = "Hello World";
    ByteArray helloByteMessage = ByteArray.wrap(helloMessage.getBytes());
    // Create the signed message
    ByteArray signedMessage = ByteArray.wrap(ecKey.sign(helloByteMessage.toBytes()).toBytes());
    String pubKey = ByteUtil.toHexString(ecKey.getAddress());
    // well formed request
    Request request = new Request(idGenerator.generateID(), ecRecoverMethod, EcRecoverParamsConverter.encode(new EcRecoverParams(helloByteMessage, signedMessage)), VersionType.Version2);
    assertEquals(pubKey, execute(request, AddressConverter::decode).toString());
    // incorrect method name
    request = new Request(idGenerator.generateID(), ecRecoverMethod + "y", EcRecoverParamsConverter.encode(new EcRecoverParams(helloByteMessage, signedMessage)), VersionType.Version2);
    try {
        execute(request, AddressConverter::decode);
        fail();
    } catch (MethodNotFoundRPCException e) {
    }
    // incorrect params
    request = new Request(idGenerator.generateID(), ecRecoverMethod, ParamUnion.wrap(new VoidParams()).encode(), VersionType.Version2);
    try {
        execute(request, AddressConverter::decode);
        fail();
    } catch (InvalidParamsRPCException e) {
    }
}
Also used : MethodNotFoundRPCException(org.aion.rpc.errors.RPCExceptions.MethodNotFoundRPCException) EcRecoverParams(org.aion.rpc.types.RPCTypes.EcRecoverParams) InvalidParamsRPCException(org.aion.rpc.errors.RPCExceptions.InvalidParamsRPCException) Request(org.aion.rpc.types.RPCTypes.Request) AddressConverter(org.aion.rpc.types.RPCTypesConverter.AddressConverter) VoidParams(org.aion.rpc.types.RPCTypes.VoidParams) ByteArray(org.aion.rpc.types.RPCTypes.ByteArray) ECKey(org.aion.crypto.ECKey) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with Request

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

the class PersonalRPCImplTest method testPersonal_unlockAccount.

@Test
public void testPersonal_unlockAccount() {
    AionAddress address = new AionAddress(ByteUtil.hexStringToBytes("a07913c03686c9659c1b614d098fd1db380a52b71fd58526b53d8107f7b355d5"));
    String password0 = "password";
    String password1 = "password1";
    int timeout0 = 300;
    Integer timeout1 = null;
    UnlockAccountParams params0 = new UnlockAccountParams(address, password0, timeout0);
    UnlockAccountParams params1 = new UnlockAccountParams(address, password1, timeout1);
    // check that the rpc library creates a default value for the duration
    assertNotNull(params1.duration);
    doReturn(false).when(chainHolder).unlockAccount(eq(address), eq(password0), anyInt());
    doReturn(true).when(chainHolder).unlockAccount(eq(address), eq(password1), anyInt());
    assertFalse(execute(new Request(idGenerator.generateID(), unlockAccountMethod, UnlockAccountParamsConverter.encode(params0), VersionType.Version2), BoolConverter::decode));
    assertTrue(execute(new Request(idGenerator.generateID(), unlockAccountMethod, UnlockAccountParamsConverter.encode(params1), VersionType.Version2), BoolConverter::decode));
}
Also used : AionAddress(org.aion.types.AionAddress) Request(org.aion.rpc.types.RPCTypes.Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UnlockAccountParams(org.aion.rpc.types.RPCTypes.UnlockAccountParams) 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