use of org.aion.rpc.types.RPCTypesConverter.AddressConverter 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.RPCTypesConverter.AddressConverter in project aion by aionnetwork.
the class PersonalRPCImplTest method testPersonal_newAccount.
@Test
public void testPersonal_newAccount() {
AionAddress expectedAddress = new AionAddress(ByteUtil.hexStringToBytes("a07913c03686c9659c1b614d098fd1db380a52b71fd58526b53d8107f7b355d5"));
String password = "password";
doReturn(expectedAddress).when(chainHolder).newAccount(anyString());
Request request = new Request(idGenerator.generateID(), newAccountMethod, PasswordParamsConverter.encode(new PasswordParams(password)), VersionType.Version2);
AionAddress responseAddress = execute(request, AddressConverter::decode);
assertEquals(expectedAddress, responseAddress);
}
Aggregations