Search in sources :

Example 1 with Transaction

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);
}
Also used : JSONObject(org.json.JSONObject) Transaction(neo.model.core.Transaction) Test(org.junit.Test)

Example 2 with Transaction

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);
}
Also used : Transaction(neo.model.core.Transaction) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 3 with Transaction

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);
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) Transaction(neo.model.core.Transaction) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Block(neo.model.core.Block) Test(org.junit.Test)

Example 4 with Transaction

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);
}
Also used : Transaction(neo.model.core.Transaction) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Block(neo.model.core.Block) Test(org.junit.Test)

Example 5 with Transaction

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());
    }
}
Also used : LocalNodeData(neo.network.model.LocalNodeData) Transaction(neo.model.core.Transaction) ScriptVerificationResultEnum(neo.model.ScriptVerificationResultEnum) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb)

Aggregations

Transaction (neo.model.core.Transaction)49 JSONObject (org.json.JSONObject)26 Block (neo.model.core.Block)25 JSONArray (org.json.JSONArray)19 TransactionOutput (neo.model.core.TransactionOutput)17 Test (org.junit.Test)14 UInt256 (neo.model.bytes.UInt256)13 TreeMap (java.util.TreeMap)12 BlockDb (neo.model.db.BlockDb)9 Map (java.util.Map)8 Fixed8 (neo.model.bytes.Fixed8)8 UInt160 (neo.model.bytes.UInt160)8 CoinReference (neo.model.core.CoinReference)8 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 LocalNodeData (neo.network.model.LocalNodeData)5 Timestamp (java.sql.Timestamp)4 UInt16 (neo.model.bytes.UInt16)4 List (java.util.List)3 TreeSet (java.util.TreeSet)3