Search in sources :

Example 6 with AionImpl

use of org.aion.zero.impl.blockchain.AionImpl in project aion by aionnetwork.

the class ApiAion0Test method testProcessGetBlockTxCountByHash.

@Test
@Ignore
public void testProcessGetBlockTxCountByHash() throws Exception {
    AionImpl impl = AionImpl.instForTest();
    AionRepositoryImpl repo = AionRepositoryImpl.inst();
    Block parentBlk = impl.getBlockchain().getBestBlock();
    AionTransaction tx = AionTransaction.create(key, repo.getNonce(AddressUtils.ZERO_ADDRESS).toByteArray(), AddressUtils.ZERO_ADDRESS, BigInteger.ONE.toByteArray(), msg, 100000, 100000, TransactionTypes.DEFAULT, null);
    Block blk = impl.getAionHub().getBlockchain().createNewMiningBlock(parentBlk, Collections.singletonList(tx), false);
    impl.getAionHub().getBlockchain().tryToConnect(blk);
    Message.req_getTransactionCountByHash reqBody = Message.req_getTransactionCountByHash.newBuilder().setTxHash(ByteString.copyFrom(blk.getHash())).build();
    rsp = sendRequest(Message.Servs.s_chain_VALUE, Message.Funcs.f_getBlockTransactionCountByHash_VALUE, reqBody.toByteArray());
    assertEquals(Message.Retcode.r_success_VALUE, rsp[1]);
    Message.rsp_getBlockTransactionCount rslt = Message.rsp_getBlockTransactionCount.parseFrom(stripHeader(rsp));
    assertEquals(1, rslt.getTxCount());
    rsp = sendRequest(Message.Servs.s_hb_VALUE, Message.Funcs.f_getBlockTransactionCountByHash_VALUE);
    assertEquals(Message.Retcode.r_fail_service_call_VALUE, rsp[1]);
}
Also used : AionImpl(org.aion.zero.impl.blockchain.AionImpl) Block(org.aion.zero.impl.types.Block) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTransaction(org.aion.base.AionTransaction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with AionImpl

use of org.aion.zero.impl.blockchain.AionImpl in project aion by aionnetwork.

the class ApiAion0Test method testProcessGetBlockTxCountByNumber.

@Test
@Ignore
public void testProcessGetBlockTxCountByNumber() throws Exception {
    AionImpl impl = AionImpl.instForTest();
    AionRepositoryImpl repo = AionRepositoryImpl.inst();
    Block parentBlk = impl.getBlockchain().getBestBlock();
    AionTransaction tx = AionTransaction.create(key, repo.getNonce(AddressUtils.ZERO_ADDRESS).toByteArray(), AddressUtils.ZERO_ADDRESS, BigInteger.ONE.toByteArray(), msg, 100000, 100000, TransactionTypes.DEFAULT, null);
    Block blk = impl.getAionHub().getBlockchain().createNewMiningBlock(parentBlk, Collections.singletonList(tx), false);
    impl.getAionHub().getBlockchain().tryToConnect(blk);
    Message.req_getBlockTransactionCountByNumber reqBody = Message.req_getBlockTransactionCountByNumber.newBuilder().setBlockNumber(blk.getNumber()).build();
    rsp = sendRequest(Message.Servs.s_chain_VALUE, Message.Funcs.f_getBlockTransactionCountByNumber_VALUE, reqBody.toByteArray());
    assertEquals(Message.Retcode.r_success_VALUE, rsp[1]);
    Message.rsp_getBlockTransactionCount rslt = Message.rsp_getBlockTransactionCount.parseFrom(stripHeader(rsp));
    assertEquals(1, rslt.getTxCount());
    rsp = sendRequest(Message.Servs.s_hb_VALUE, Message.Funcs.f_getBlockTransactionCountByNumber_VALUE);
    assertEquals(Message.Retcode.r_fail_service_call_VALUE, rsp[1]);
}
Also used : AionImpl(org.aion.zero.impl.blockchain.AionImpl) Block(org.aion.zero.impl.types.Block) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTransaction(org.aion.base.AionTransaction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with AionImpl

use of org.aion.zero.impl.blockchain.AionImpl in project aion by aionnetwork.

the class ApiAion0Test method testProcessGetTxCount.

@Test
@Ignore
public void testProcessGetTxCount() throws Exception {
    AionImpl impl = AionImpl.instForTest();
    AionRepositoryImpl repo = AionRepositoryImpl.inst();
    Block parentBlk = impl.getBlockchain().getBestBlock();
    AionTransaction tx = AionTransaction.create(key, repo.getNonce(AddressUtils.ZERO_ADDRESS).toByteArray(), AddressUtils.ZERO_ADDRESS, BigInteger.ONE.toByteArray(), msg, 100000, 100000, TransactionTypes.DEFAULT, null);
    Block blk = impl.getAionHub().getBlockchain().createNewMiningBlock(parentBlk, Collections.singletonList(tx), false);
    impl.getAionHub().getBlockchain().tryToConnect(blk);
    blk = api.getBlockByHash(blk.getHash());
    Message.req_getTransactionCount reqBody = Message.req_getTransactionCount.newBuilder().setBlocknumber(blk.getNumber()).setAddress(ByteString.copyFrom(blk.getTransactionsList().get(0).getSenderAddress().toByteArray())).build();
    rsp = sendRequest(Message.Servs.s_chain_VALUE, Message.Funcs.f_getTransactionCount_VALUE, reqBody.toByteArray());
    assertEquals(Message.Retcode.r_success_VALUE, rsp[1]);
    Message.rsp_getTransactionCount rslt = Message.rsp_getTransactionCount.parseFrom(stripHeader(rsp));
    assertEquals(1, rslt.getTxCount());
    rsp = sendRequest(Message.Servs.s_hb_VALUE, Message.Funcs.f_getTransactionCount_VALUE);
    assertEquals(Message.Retcode.r_fail_service_call_VALUE, rsp[1]);
}
Also used : AionImpl(org.aion.zero.impl.blockchain.AionImpl) Block(org.aion.zero.impl.types.Block) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTransaction(org.aion.base.AionTransaction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with AionImpl

use of org.aion.zero.impl.blockchain.AionImpl in project aion by aionnetwork.

the class ApiAion0Test method testProcessGetTR.

@Test
@Ignore
public void testProcessGetTR() throws Exception {
    AionImpl impl = AionImpl.instForTest();
    AionRepositoryImpl repo = AionRepositoryImpl.inst();
    Block parentBlk = impl.getBlockchain().getBestBlock();
    AionTransaction tx = AionTransaction.create(key, repo.getNonce(AddressUtils.ZERO_ADDRESS).toByteArray(), AddressUtils.ZERO_ADDRESS, BigInteger.ONE.toByteArray(), msg, 100000, 100000, TransactionTypes.DEFAULT, null);
    Block blk = impl.getAionHub().getBlockchain().createNewMiningBlock(parentBlk, Collections.singletonList(tx), false);
    impl.getAionHub().getBlockchain().tryToConnect(blk);
    Message.req_getTransactionReceipt reqBody = Message.req_getTransactionReceipt.newBuilder().setTxHash(ByteString.copyFrom(tx.getTransactionHash())).build();
    rsp = sendRequest(Message.Servs.s_tx_VALUE, Message.Funcs.f_getTransactionReceipt_VALUE, reqBody.toByteArray());
    assertEquals(Message.Retcode.r_success_VALUE, rsp[1]);
    Message.rsp_getTransactionReceipt rslt = Message.rsp_getTransactionReceipt.parseFrom(stripHeader(rsp));
    assertEquals(ByteString.copyFrom(AddressUtils.ZERO_ADDRESS.toByteArray()), rslt.getTo());
    rsp = sendRequest(Message.Servs.s_hb_VALUE, Message.Funcs.f_getTransactionReceipt_VALUE);
    assertEquals(Message.Retcode.r_fail_service_call_VALUE, rsp[1]);
}
Also used : AionImpl(org.aion.zero.impl.blockchain.AionImpl) Block(org.aion.zero.impl.types.Block) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTransaction(org.aion.base.AionTransaction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with AionImpl

use of org.aion.zero.impl.blockchain.AionImpl 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

AionImpl (org.aion.zero.impl.blockchain.AionImpl)10 Test (org.junit.Test)9 AionTransaction (org.aion.base.AionTransaction)7 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)7 Block (org.aion.zero.impl.types.Block)7 Ignore (org.junit.Ignore)7 Request (org.aion.rpc.types.RPCTypes.Request)2 AionBlockchainImpl (org.aion.zero.impl.blockchain.AionBlockchainImpl)2 SubmissionResult (org.aion.rpc.types.RPCTypes.SubmissionResult)1 SubmitBlockParams (org.aion.rpc.types.RPCTypes.SubmitBlockParams)1 SubmitSignatureParams (org.aion.rpc.types.RPCTypes.SubmitSignatureParams)1 SubmissionResultConverter (org.aion.rpc.types.RPCTypesConverter.SubmissionResultConverter)1 ImportResult (org.aion.zero.impl.core.ImportResult)1 MiningBlock (org.aion.zero.impl.types.MiningBlock)1 StakingBlock (org.aion.zero.impl.types.StakingBlock)1