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));
}
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));
}
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));
}
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) {
}
}
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));
}
Aggregations