Search in sources :

Example 1 with SubmitSignatureParams

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

the class StakingRPCImplTest method testSubmitSignature.

@Test
public void testSubmitSignature() {
    assertTrue(execute(new Request(1, "submitsignature", SubmitSignatureParamsConverter.encode(new SubmitSignatureParams(validSignature, validSealHash)), VersionType.Version2), BoolConverter::decode));
    assertFalse(execute(new Request(1, "submitsignature", SubmitSignatureParamsConverter.encode(new SubmitSignatureParams(invalidSignature, invalidSealHash)), VersionType.Version2), BoolConverter::decode));
    try {
        execute(new Request(1, "submitsignature", SubmitSignatureParamsConverter.encode(new SubmitSignatureParams(invalidSignature, missingSealHash)), null), BoolConverter::decode);
        fail();
    } catch (BlockTemplateNotFoundRPCException e) {
    // We expect this exception
    }
}
Also used : SubmitSignatureParams(org.aion.rpc.types.RPCTypes.SubmitSignatureParams) Request(org.aion.rpc.types.RPCTypes.Request) BoolConverter(org.aion.rpc.types.RPCTypesConverter.BoolConverter) BlockTemplateNotFoundRPCException(org.aion.rpc.errors.RPCExceptions.BlockTemplateNotFoundRPCException) Test(org.junit.Test)

Example 2 with SubmitSignatureParams

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

the class StakingRPCImplTest method testTimeStampInSubmitSignature.

@Test
public void testTimeStampInSubmitSignature() {
    StakingBlock blockWithRightTimestamp = new StakingBlock(new byte[StakingBlockHeader.HASH_BYTE_SIZE], AddressUtils.ZERO_ADDRESS, new byte[StakingBlockHeader.BLOOM_BYTE_SIZE], new byte[StakingBlockHeader.MAX_DIFFICULTY_LENGTH], 0, (System.currentTimeMillis() / 1000), new byte[0], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new ArrayList<>(), 0, 0, DEFAULT_SIGNATURE, validSeed.toBytes(), validSigningPublicKey.toBytes());
    byte[] validSealHash = blockWithRightTimestamp.getHeader().getMineHash();
    AionImpl aionImpl = mock(AionImpl.class);
    AionBlockchainImpl chainImpl = mock(AionBlockchainImpl.class);
    chainHolder = spy(new AionChainHolder(aionImpl, accountManager));
    doReturn(true).when(chainHolder).isUnityForkEnabled();
    doReturn(chainImpl).when(aionImpl).getBlockchain();
    doReturn(blockWithRightTimestamp).when(chainImpl).getCachingStakingBlockTemplate(validSealHash);
    doReturn(true).when(chainHolder).addNewBlock(blockWithRightTimestamp);
    doCallRealMethod().when(chainHolder).submitSignature(validSignature.toBytes(), validSealHash);
    rpcMethods = new RPCMethods(chainHolder);
    String method = "submitsignature";
    assertTrue(execute(new Request(1, method, SubmitSignatureParamsConverter.encode(new SubmitSignatureParams(validSignature, ByteArray.wrap(validSealHash))), VersionType.Version2), BoolConverter::decode));
    // Now we test current timestamp + 1 (for testing the clock drift)
    StakingBlock blockWithRightTimestamp1 = new StakingBlock(new byte[StakingBlockHeader.HASH_BYTE_SIZE], AddressUtils.ZERO_ADDRESS, new byte[StakingBlockHeader.BLOOM_BYTE_SIZE], new byte[StakingBlockHeader.MAX_DIFFICULTY_LENGTH], 0, (System.currentTimeMillis() / 1000 + 1), new byte[0], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new ArrayList<>(), 0, 0, DEFAULT_SIGNATURE, validSeed.toBytes(), validSigningPublicKey.toBytes());
    validSealHash = blockWithRightTimestamp1.getHeader().getMineHash();
    doReturn(blockWithRightTimestamp1).when(chainImpl).getCachingStakingBlockTemplate(validSealHash);
    doReturn(true).when(chainHolder).addNewBlock(blockWithRightTimestamp1);
    assertTrue(execute(new Request(1, method, SubmitSignatureParamsConverter.encode(new SubmitSignatureParams(validSignature, ByteArray.wrap(validSealHash))), VersionType.Version2), BoolConverter::decode));
    // Now we test the future block timestamp (timestamp + 2)
    StakingBlock futureBlock = new StakingBlock(new byte[StakingBlockHeader.HASH_BYTE_SIZE], AddressUtils.ZERO_ADDRESS, new byte[StakingBlockHeader.BLOOM_BYTE_SIZE], new byte[StakingBlockHeader.MAX_DIFFICULTY_LENGTH], 0, (System.currentTimeMillis() / 1000 + 2), new byte[0], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new byte[StakingBlockHeader.HASH_BYTE_SIZE], new ArrayList<>(), 0, 0, DEFAULT_SIGNATURE, validSeed.toBytes(), validSigningPublicKey.toBytes());
    validSealHash = futureBlock.getHeader().getMineHash();
    doReturn(futureBlock).when(chainImpl).getCachingStakingBlockTemplate(validSealHash);
    doReturn(true).when(chainHolder).addNewBlock(futureBlock);
    assertTrue(execute(new Request(1, method, SubmitSignatureParamsConverter.encode(new SubmitSignatureParams(validSignature, ByteArray.wrap(validSealHash))), VersionType.Version2), BoolConverter::decode));
}
Also used : AionImpl(org.aion.zero.impl.blockchain.AionImpl) SubmitSignatureParams(org.aion.rpc.types.RPCTypes.SubmitSignatureParams) Request(org.aion.rpc.types.RPCTypes.Request) AionBlockchainImpl(org.aion.zero.impl.blockchain.AionBlockchainImpl) StakingBlock(org.aion.zero.impl.types.StakingBlock) Test(org.junit.Test)

Aggregations

Request (org.aion.rpc.types.RPCTypes.Request)2 SubmitSignatureParams (org.aion.rpc.types.RPCTypes.SubmitSignatureParams)2 Test (org.junit.Test)2 BlockTemplateNotFoundRPCException (org.aion.rpc.errors.RPCExceptions.BlockTemplateNotFoundRPCException)1 BoolConverter (org.aion.rpc.types.RPCTypesConverter.BoolConverter)1 AionBlockchainImpl (org.aion.zero.impl.blockchain.AionBlockchainImpl)1 AionImpl (org.aion.zero.impl.blockchain.AionImpl)1 StakingBlock (org.aion.zero.impl.types.StakingBlock)1