use of org.aion.rpc.types.RPCTypes.Request 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));
}
Aggregations