use of neo.model.core.Block in project neo-java by coranos.
the class TestRpcServer method test021CityOfZionGetHistory.
/**
* test CoZ gethistory.
*/
@Test
public void test021CityOfZionGetHistory() {
final JSONArray params = new JSONArray();
final Block block = CONTROLLER.getLocalNodeData().getBlockDb().getFullBlockFromHeight(0);
final Transaction transaction = block.getTransactionList().get(block.getTransactionList().size() - 1);
final TransactionOutput to = transaction.outputs.get(0);
final String address = ModelUtil.scriptHashToAddress(to.scriptHash);
final String uri = CityOfZionCommandEnum.HISTORY.getUriPrefix() + address;
final String method = CoreRpcCommandEnum.UNKNOWN.getName();
final String expectedStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test021CityOfZionGetHistory");
CityOfZionCommandEnum.getCommandStartingWith(uri);
final String actualStrRaw = TestRpcServerUtil.getResponse(CONTROLLER, uri, RpcServerUtil.VERSION_2_0, params, method);
final String expectedStr = new JSONObject(expectedStrRaw).toString(2);
final String actualStr = new JSONObject(actualStrRaw).toString(2);
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedStr, actualStr);
}
use of neo.model.core.Block in project neo-java by coranos.
the class TestRpcServer method test013CityOfZionGetTransaction.
/**
* test reading core address with no subcategory.
*/
@Test
public void test013CityOfZionGetTransaction() {
final JSONArray params = new JSONArray();
final Block block = CONTROLLER.getLocalNodeData().getBlockDb().getFullBlockFromHeight(0);
final Transaction transaction = block.getTransactionList().get(0);
final String txHash = transaction.getHash().toHexString();
final String uri = CityOfZionCommandEnum.TRANSACTION.getUriPrefix() + txHash;
final String method = CoreRpcCommandEnum.UNKNOWN.getName();
final String expectedStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test013CityOfZionGetTransaction");
CityOfZionCommandEnum.getCommandStartingWith(uri);
final String actualStrRaw = TestRpcServerUtil.getResponse(CONTROLLER, uri, RpcServerUtil.VERSION_2_0, params, method);
final String expectedStr = new JSONObject(expectedStrRaw).toString(2);
final String actualStr = new JSONObject(actualStrRaw).toString(2);
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedStr, actualStr);
}
use of neo.model.core.Block in project neo-java by coranos.
the class TestVm method testTransaction.
private void testTransaction(final long blockHeight, final int txIx) {
final LocalNodeData localNodeData = CONTROLLER.getLocalNodeData();
final BlockDb blockDb = localNodeData.getBlockDb();
final Block block = blockDb.getFullBlockFromHeight(blockHeight);
final int maxTxIx = block.getTransactionList().size();
final Transaction tx = block.getTransactionList().get(txIx);
final long maxIndex = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
LOG.info("STARTED block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
final ScriptVerificationResultEnum verifyScriptsResult = VerifyScriptUtil.verifyScripts(blockDb, tx);
if (!verifyScriptsResult.equals(ScriptVerificationResultEnum.PASS)) {
LOG.error("FAILURE block {} of {} tx {} of {} : {} {} : {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash(), verifyScriptsResult);
throw new RuntimeException("script failed : " + verifyScriptsResult);
} else {
LOG.info("SUCCESS block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
}
}
use of neo.model.core.Block in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getTransactionWithAccountList.
@Override
public List<Transaction> getTransactionWithAccountList(final UInt160 account) {
final List<Transaction> transactionList = new ArrayList<>();
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (final Transaction transaction : block.getTransactionList()) {
boolean transactionHasAccount = false;
for (final TransactionOutput output : transaction.outputs) {
if (output.scriptHash.equals(account)) {
transactionHasAccount = true;
}
}
if (transactionHasAccount) {
transactionList.add(transaction);
}
}
}
return transactionList;
}
use of neo.model.core.Block in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getTransactionWithHash.
@Override
public final Transaction getTransactionWithHash(final UInt256 hash) {
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (final Transaction transaction : block.getTransactionList()) {
if (transaction.getHash().equals(hash)) {
return transaction;
}
}
}
throw new RuntimeException("no transaction with hash:" + hash);
}
Aggregations