use of neo.model.core.Transaction in project neo-java by coranos.
the class TestNEP5 method test001Error6d07.
/**
* test TransactionType.valueOfByte.
*/
@Test
public void test001Error6d07() {
final String expectedHexStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test001Error6d07Hex");
final String transactionHex = TestUtil.fromHexJsonObject(new JSONObject(expectedHexStrRaw));
final Transaction transaction = new Transaction(ByteBuffer.wrap(ModelUtil.decodeHex(transactionHex)));
final String expectedStr = new JSONObject(TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test001Error6d07")).toString();
final String actualStr = transaction.toString();
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedStr, actualStr);
final String expectedHexStr = new JSONObject(expectedHexStrRaw).toString();
final String actualHexStr = TestUtil.toHexJsonObject(ModelUtil.toHexString(transaction.toByteArray())).toString();
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedHexStr, actualHexStr);
}
use of neo.model.core.Transaction in project neo-java by coranos.
the class TestRpcServer method test011CoreGetTransactionOutputNoOutputs.
/**
* test reading core address with no subcategory.
*/
@Test
public void test011CoreGetTransactionOutputNoOutputs() {
final JSONArray params = new JSONArray();
final Transaction transaction = CONTROLLER.getLocalNodeData().getBlockDb().getFullBlockFromHeight(0).getTransactionList().get(0);
final String txHash = transaction.getHash().toHexString();
params.put(txHash);
params.put(0);
final String method = CoreRpcCommandEnum.GETTXOUT.getName();
final String expectedStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test011CoreGetTransactionOutputNoOutputs");
final String actualStrRaw = TestRpcServerUtil.getResponse(CONTROLLER, "", 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.Transaction 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.Transaction 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.Transaction 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());
}
}
Aggregations