Search in sources :

Example 1 with VoidParams

use of org.aion.rpc.types.RPCTypes.VoidParams 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 VoidParams

use of org.aion.rpc.types.RPCTypes.VoidParams 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 VoidParams

use of org.aion.rpc.types.RPCTypes.VoidParams 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 4 with VoidParams

use of org.aion.rpc.types.RPCTypes.VoidParams 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)

Aggregations

Request (org.aion.rpc.types.RPCTypes.Request)4 VoidParams (org.aion.rpc.types.RPCTypes.VoidParams)4 Test (org.junit.Test)4 BigInteger (java.math.BigInteger)1 ECKey (org.aion.crypto.ECKey)1 InvalidParamsRPCException (org.aion.rpc.errors.RPCExceptions.InvalidParamsRPCException)1 MethodNotFoundRPCException (org.aion.rpc.errors.RPCExceptions.MethodNotFoundRPCException)1 UnsupportedUnityFeatureRPCException (org.aion.rpc.errors.RPCExceptions.UnsupportedUnityFeatureRPCException)1 BlockTemplate (org.aion.rpc.types.RPCTypes.BlockTemplate)1 ByteArray (org.aion.rpc.types.RPCTypes.ByteArray)1 EcRecoverParams (org.aion.rpc.types.RPCTypes.EcRecoverParams)1 RPCTypesConverter (org.aion.rpc.types.RPCTypesConverter)1 AddressConverter (org.aion.rpc.types.RPCTypesConverter.AddressConverter)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1