Search in sources :

Example 1 with Block

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);
}
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 2 with Block

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);
}
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 3 with Block

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());
    }
}
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)

Example 4 with Block

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

Example 5 with Block

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

Aggregations

Block (neo.model.core.Block)65 Test (org.junit.Test)26 Transaction (neo.model.core.Transaction)25 JSONObject (org.json.JSONObject)24 JSONArray (org.json.JSONArray)16 TransactionOutput (neo.model.core.TransactionOutput)9 BlockDb (neo.model.db.BlockDb)9 IOException (java.io.IOException)8 TreeMap (java.util.TreeMap)8 UInt256 (neo.model.bytes.UInt256)8 LocalNodeData (neo.network.model.LocalNodeData)6 Fixed8 (neo.model.bytes.Fixed8)5 Timestamp (java.sql.Timestamp)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 OutputStream (java.io.OutputStream)3 SQLException (java.sql.SQLException)3 UInt160 (neo.model.bytes.UInt160)3 UInt32 (neo.model.bytes.UInt32)3