本文整理汇总了Java中org.ethereum.util.blockchain.StandaloneBlockchain类的典型用法代码示例。如果您正苦于以下问题:Java StandaloneBlockchain类的具体用法?Java StandaloneBlockchain怎么用?Java StandaloneBlockchain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StandaloneBlockchain类属于org.ethereum.util.blockchain包,在下文中一共展示了StandaloneBlockchain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: backwardCompatibleDbTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void backwardCompatibleDbTest() {
// check that we can read previously saved entries (saved with legacy code)
HashMapDB txDb = new HashMapDB();
TransactionStore transactionStore = new TransactionStore(txDb);
StandaloneBlockchain bc = new StandaloneBlockchain();
bc.getBlockchain().withTransactionStore(transactionStore);
bc.sendEther(new byte[20], BigInteger.valueOf(1000));
Block b1 = bc.createBlock();
Transaction tx = b1.getTransactionsList().get(0);
TransactionInfo info = transactionStore.get(tx.getHash()).get(0);
HashMapDB<byte[]> txDb1 = new HashMapDB<>();
txDb1.put(tx.getHash(), info.getEncoded()); // legacy serialization
TransactionStore transactionStore1 = new TransactionStore(txDb1);
TransactionInfo info1 = transactionStore1.get(tx.getHash()).get(0);
Assert.assertArrayEquals(info1.getReceipt().getPostTxState(), info.getReceipt().getPostTxState());
}
示例2: constructorTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void constructorTest() {
StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true);
SolidityContract a = sb.submitNewContract(
"contract A {" +
" uint public a;" +
" uint public b;" +
" function A(uint a_, uint b_) {a = a_; b = b_; }" +
"}",
"A", 555, 777
);
Assert.assertEquals(BigInteger.valueOf(555), a.callConstFunction("a")[0]);
Assert.assertEquals(BigInteger.valueOf(777), a.callConstFunction("b")[0]);
SolidityContract b = sb.submitNewContract(
"contract A {" +
" string public a;" +
" uint public b;" +
" function A(string a_, uint b_) {a = a_; b = b_; }" +
"}",
"A", "This string is longer than 32 bytes...", 777
);
Assert.assertEquals("This string is longer than 32 bytes...", b.callConstFunction("a")[0]);
Assert.assertEquals(BigInteger.valueOf(777), b.callConstFunction("b")[0]);
}
示例3: shouldLoadGenesis_withCodeAndNonceInAlloc
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void shouldLoadGenesis_withCodeAndNonceInAlloc() {
final Genesis genesis = GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-alloc.json"));
final StandaloneBlockchain bc = new StandaloneBlockchain();
bc.withGenesis(genesis);
final byte[] account = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
byte[] expectedCode = Hex.decode("00ff00");
long expectedNonce = 255; //FF
final BigInteger actualNonce = bc.getBlockchain().getRepository().getNonce(account);
final byte[] actualCode = bc.getBlockchain().getRepository().getCode(account);
assertEquals(BigInteger.valueOf(expectedNonce), actualNonce);
assertTrue(equal(expectedCode, actualCode));
}
示例4: testBlockOnlyIncluded
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void testBlockOnlyIncluded() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3_ = bc.createForkBlock(b2_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), PENDING);
}
示例5: branchTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void branchTest() throws Exception {
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount);
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract contr = bc.submitNewContract(
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
"}");
Block b1 = bc.createBlock();
contr.callFunction("set", 0xaaaaaaaaaaaaL);
Block b2 = bc.createBlock();
contr.callFunction("set", 0xbbbbbbbbbbbbL);
Block b2_ = bc.createForkBlock(b1);
bc.createForkBlock(b2);
bc.createBlock();
bc.createBlock();
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr.callConstFunction("n")[0]);
}
示例6: main
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Creating a blockchain which generates a new block for each transaction
// just not to call createBlock() after each call transaction
StandaloneBlockchain bc = new StandaloneBlockchain().withAutoblock(true);
System.out.println("Creating first empty block (need some time to generate DAG)...");
// warning up the block miner just to understand how long
// the initial miner dataset is generated
bc.createBlock();
System.out.println("Creating a contract...");
// This compiles our Solidity contract, submits it to the blockchain
// internally generates the block with this transaction and returns the
// contract interface
SolidityContract calc = bc.submitNewContract(contractSrc);
System.out.println("Calculating...");
// Creates the contract call transaction, submits it to the blockchain
// and generates a new block which includes this transaction
// After new block is generated the contract state is changed
calc.callFunction("add", 100);
// Check the contract state with a constant call which returns result
// but doesn't generate any transactions and remain the contract state unchanged
assertEqual(BigInteger.valueOf(100), (BigInteger) calc.callConstFunction("result")[0]);
calc.callFunction("add", 200);
assertEqual(BigInteger.valueOf(300), (BigInteger) calc.callConstFunction("result")[0]);
calc.callFunction("mul", 10);
assertEqual(BigInteger.valueOf(3000), (BigInteger) calc.callConstFunction("result")[0]);
calc.callFunction("div", 5);
assertEqual(BigInteger.valueOf(600), (BigInteger) calc.callConstFunction("result")[0]);
System.out.println("Clearing...");
calc.callFunction("clear");
assertEqual(BigInteger.valueOf(0), (BigInteger) calc.callConstFunction("result")[0]);
// We are done - the Solidity contract worked as expected.
System.out.println("Done.");
}
示例7: myTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void myTest() throws Exception {
// check that IndexedStore rebranch changes are persisted
StandaloneBlockchain bc = new StandaloneBlockchain().withGasPrice(1);
IndexedBlockStore ibs = (IndexedBlockStore) bc.getBlockchain().getBlockStore();
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(bc.getBlockchain().getBestBlock().isEqual(b2));
Block b3_ = bc.createForkBlock(b2_);
Assert.assertTrue(bc.getBlockchain().getBestBlock().isEqual(b3_));
Block sb2 = bc.getBlockchain().getBlockStore().getChainBlockByNumber(2);
Block sb3 = bc.getBlockchain().getBlockStore().getChainBlockByNumber(3);
Assert.assertTrue(sb2.isEqual(b2_));
Assert.assertTrue(sb3.isEqual(b3_));
Block b4_ = bc.createBlock();
bc.getBlockchain().flush();
IndexedBlockStore ibs1 = new IndexedBlockStore();
ibs1.init(ibs.indexDS, ibs.blocksDS);
sb2 = ibs1.getChainBlockByNumber(2);
sb3 = ibs1.getChainBlockByNumber(3);
Block sb4 = ibs1.getChainBlockByNumber(4);
Assert.assertTrue(sb2.isEqual(b2_));
Assert.assertTrue(sb3.isEqual(b3_));
Assert.assertTrue(sb4.isEqual(b4_));
}
示例8: simpleTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void simpleTest() {
String contractSrc =
"contract Adder {" +
" function add(int a, int b) returns (int) {return a + b;}" +
"}";
HashMapDB<byte[]> txDb = new HashMapDB<>();
StandaloneBlockchain bc = new StandaloneBlockchain();
bc.getBlockchain().withTransactionStore(new TransactionStore(txDb));
SolidityContract contract = bc.submitNewContract(contractSrc);
bc.createBlock();
contract.callFunction("add", 555, 222);
Block b2 = bc.createBlock();
contract.callFunction("add", 333, 333);
Block b3 = bc.createBlock();
Transaction tx1 = b2.getTransactionsList().get(0);
TransactionInfo tx1Info = bc.getBlockchain().getTransactionInfo(tx1.getHash());
byte[] executionResult = tx1Info.getReceipt().getExecutionResult();
Assert.assertArrayEquals(new DataWord(777).getData(), executionResult);
System.out.println(txDb.keys().size());
bc.getBlockchain().flush();
System.out.println(txDb.keys().size());
TransactionStore txStore = new TransactionStore(txDb);
TransactionInfo tx1Info_ = txStore.get(tx1.getHash()).get(0);
executionResult = tx1Info_.getReceipt().getExecutionResult();
Assert.assertArrayEquals(new DataWord(777).getData(), executionResult);
TransactionInfo highIndex = new TransactionInfo(tx1Info.getReceipt(), tx1Info.getBlockHash(), 255);
TransactionInfo highIndexCopy = new TransactionInfo(highIndex.getEncoded());
Assert.assertArrayEquals(highIndex.getBlockHash(), highIndexCopy.getBlockHash());
Assert.assertEquals(highIndex.getIndex(), highIndexCopy.getIndex());
}
示例9: forkTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void forkTest() {
// check that TransactionInfo is always returned from the main chain for
// transaction which included into blocks from different forks
String contractSrc =
"contract Adder {" +
" int public lastResult;" +
" function add(int a, int b) returns (int) {lastResult = a + b; return lastResult; }" +
"}";
HashMapDB txDb = new HashMapDB();
StandaloneBlockchain bc = new StandaloneBlockchain();
TransactionStore transactionStore = new TransactionStore(txDb);
bc.getBlockchain().withTransactionStore(transactionStore);
SolidityContract contract = bc.submitNewContract(contractSrc);
Block b1 = bc.createBlock();
contract.callFunction("add", 555, 222);
Block b2 = bc.createBlock();
Transaction tx1 = b2.getTransactionsList().get(0);
TransactionInfo txInfo = bc.getBlockchain().getTransactionInfo(tx1.getHash());
Assert.assertTrue(Arrays.equals(txInfo.getBlockHash(), b2.getHash()));
Block b2_ = bc.createForkBlock(b1);
contract.callFunction("add", 555, 222); // tx with the same hash as before
Block b3_ = bc.createForkBlock(b2_);
TransactionInfo txInfo_ = bc.getBlockchain().getTransactionInfo(tx1.getHash());
Assert.assertTrue(Arrays.equals(txInfo_.getBlockHash(), b3_.getHash()));
Block b3 = bc.createForkBlock(b2);
Block b4 = bc.createForkBlock(b3);
txInfo = bc.getBlockchain().getTransactionInfo(tx1.getHash());
Assert.assertTrue(Arrays.equals(txInfo.getBlockHash(), b2.getHash()));
}
示例10: testDaoExtraData
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void testDaoExtraData() {
final StandaloneBlockchain sb = createBlockchain(true);
for (int i = 0; i < FORK_BLOCK + 30; i++) {
Block b = sb.createBlock();
// System.out.println("Created block " + b.getNumber() + " " + getData(b.getExtraData()));
}
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK - 1));
assertEquals("dao-hard-fork", getData(sb, FORK_BLOCK));
assertEquals("dao-hard-fork", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED - 1));
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED));
}
示例11: testNoDaoExtraData
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void testNoDaoExtraData() {
final StandaloneBlockchain sb = createBlockchain(false);
for (int i = 0; i < FORK_BLOCK + 30; i++) {
Block b = sb.createBlock();
}
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK - 1));
assertEquals("", getData(sb, FORK_BLOCK));
assertEquals("", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED - 1));
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED));
}
示例12: createBlockchain
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
private StandaloneBlockchain createBlockchain(boolean proFork) {
final BaseNetConfig netConfig = new BaseNetConfig();
final FrontierConfig c1 = StandaloneBlockchain.getEasyMiningConfig();
netConfig.add(0, StandaloneBlockchain.getEasyMiningConfig());
netConfig.add(FORK_BLOCK, proFork ? new DaoHFConfig(c1, FORK_BLOCK) : new DaoNoHFConfig(c1, FORK_BLOCK));
// create blockchain
return new StandaloneBlockchain()
.withAutoblock(true)
.withNetConfig(netConfig);
}
示例13: encodeTest1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void encodeTest1() {
StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true);
SolidityContract a = sb.submitNewContract(
"contract A {" +
" uint public a;" +
" function f(uint a_) {a = a_;}" +
"}");
a.callFunction("f", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
BigInteger r = (BigInteger) a.callConstFunction("a")[0];
System.out.println(r.toString(16));
Assert.assertEquals(new BigInteger(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), r);
}
示例14: invalidTxTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@Test
public void invalidTxTest() {
// check that invalid tx doesn't break implementation
StandaloneBlockchain sb = new StandaloneBlockchain();
ECKey alice = sb.getSender();
ECKey bob = new ECKey();
sb.sendEther(bob.getAddress(), BigInteger.valueOf(1000));
sb.setSender(bob);
sb.sendEther(alice.getAddress(), BigInteger.ONE);
sb.setSender(alice);
sb.sendEther(bob.getAddress(), BigInteger.valueOf(2000));
sb.createBlock();
}
示例15: setup
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入依赖的package包/类
@BeforeClass
public static void setup() throws IOException, URISyntaxException {
nodeA = new Node("enode://3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0[email protected]localhost:30334");
SysPropConfigA.props.overrideParams(
"peer.listen.port", "30334",
"peer.privateKey", "3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c",
// nodeId: 3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0f0fffed115dd2d4b5ca1929287839dcd4e77bdc724302b44ae48622a8766ee6
"genesis", "genesis-light-old.json"
);
SysPropConfigA.props.setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig());
SysPropConfigB.props.overrideParams(
"peer.listen.port", "30335",
"peer.privateKey", "6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec",
"genesis", "genesis-light-old.json",
"sync.enabled", "true",
"sync.max.hashes.ask", "3",
"sync.max.blocks.ask", "2"
);
SysPropConfigB.props.setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig());
/*
1 => ed1b6f07d738ad92c5bdc3b98fe25afea9c863dd351711776d9ce1ffb9e3d276
2 => 43808666b662d131c6cff336a0d13608767ead9c9d5f181e95caa3597f3faf14
3 => 1b5c231211f500bc73148dc9d9bdb9de2265465ba441a0db1790ba4b3f5f3e9c
4 => db517e04399dbf5a65caf6b2572b3966c8f98a1d29b1e50dc8db51e54c15d83d
5 => c42d6dbaa756eda7f4244a3507670d764232bd7068d43e6d8ef680c6920132f6
6 => 604c92e8d16dafb64134210d521fcc85aec27452e75aedf708ac72d8240585d3
7 => 3f51b0471eb345b1c5f3c6628e69744358ff81d3f64a3744bbb2edf2adbb0ebc
8 => 62cfd04e29d941954e68ac8ca18ef5cd78b19809eaed860ae72589ebad53a21d
9 => d32fc8e151f158d52fe0be6cba6d0b5c20793a00c4ad0d32db8ccd9269199a29
10 => 22d8c1d909eb142ea0d69d0a38711874f98d6eef1bc669836da36f6b557e9564
*/
mainB1B10 = loadBlocks("sync/main-b1-b10.dmp");
b10 = mainB1B10.get(mainB1B10.size() - 1);
}