本文整理汇总了Java中org.ethereum.util.blockchain.StandaloneBlockchain.createForkBlock方法的典型用法代码示例。如果您正苦于以下问题:Java StandaloneBlockchain.createForkBlock方法的具体用法?Java StandaloneBlockchain.createForkBlock怎么用?Java StandaloneBlockchain.createForkBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.util.blockchain.StandaloneBlockchain
的用法示例。
在下文中一共展示了StandaloneBlockchain.createForkBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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]);
}
示例3: 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_));
}
示例4: 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()));
}
示例5: simpleFork
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void simpleFork() {
StandaloneBlockchain sb = new StandaloneBlockchain();
Block b1 = sb.createBlock();
Block b2_ = sb.createBlock();
Block b3_ = sb.createForkBlock(b2_);
Block b2 = sb.createForkBlock(b1);
Block b3 = sb.createForkBlock(b2);
Block b4 = sb.createForkBlock(b3);
Block b5 = sb.createForkBlock(b4);
}
示例6: simpleRebranch
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void simpleRebranch() {
StandaloneBlockchain sb = new StandaloneBlockchain();
Block b0 = sb.getBlockchain().getBestBlock();
ECKey addr1 = ECKey.fromPrivate(HashUtil.sha3("1".getBytes()));
BigInteger bal2 = sb.getBlockchain().getRepository().getBalance(sb.getSender().getAddress());
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(100));
Block b1 = sb.createBlock();
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(100));
Block b2 = sb.createBlock();
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(100));
Block b3 = sb.createBlock();
BigInteger bal1 = sb.getBlockchain().getRepository().getBalance(addr1.getAddress());
Assert.assertEquals(BigInteger.valueOf(300), bal1);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b1_ = sb.createForkBlock(b0);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b2_ = sb.createForkBlock(b1_);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b3_ = sb.createForkBlock(b2_);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b4_ = sb.createForkBlock(b3_);
BigInteger bal1_ = sb.getBlockchain().getRepository().getBalance(addr1.getAddress());
Assert.assertEquals(BigInteger.valueOf(800), bal1_);
// BigInteger bal2_ = sb.getBlockchain().getRepository().getBalance(sb.getSender().getAddress());
// Assert.assertEquals(bal2, bal2_);
}
示例7: createContractFork1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void createContractFork1() throws Exception {
// Test creation of the contract on forked branch with different storage
String contractSrc =
"contract A {" +
" int public a;" +
" function A() {" +
" a = 333;" +
" }" +
"}" +
"contract B {" +
" int public a;" +
" function B() {" +
" a = 111;" +
" }" +
"}";
{
StandaloneBlockchain bc = new StandaloneBlockchain();
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
SolidityContract a = bc.submitNewContract(contractSrc, "A");
Block b3 = bc.createBlock();
SolidityContract b = bc.submitNewContract(contractSrc, "B");
Block b2_ = bc.createForkBlock(b1);
Assert.assertEquals(BigInteger.valueOf(333), a.callConstFunction("a")[0]);
Assert.assertEquals(BigInteger.valueOf(111), b.callConstFunction(b2_, "a")[0]);
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("a")[0]);
Assert.assertEquals(BigInteger.valueOf(333), a.callConstFunction(b3, "a")[0]);
}
}
示例8: contractCodeForkTest
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void contractCodeForkTest() throws IOException, InterruptedException {
String contractA =
"contract A {" +
" function call() returns (uint) {" +
" return 111;" +
" }" +
"}";
String contractB =
"contract B {" +
" function call() returns (uint) {" +
" return 222222;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
Block b1 = bc.createBlock();
SolidityContract a = bc.submitNewContract(contractA);
Block b2 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("call")[0]);
SolidityContract b = bc.submitNewContract(contractB);
Block b2_ = bc.createForkBlock(b1);
Block b3 = bc.createForkBlock(b2);
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("call")[0]);
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction(b2, "call")[0]);
Assert.assertEquals(BigInteger.valueOf(222222), b.callConstFunction(b2_, "call")[0]);
}
示例9: prevBlockHashOnFork
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void prevBlockHashOnFork() throws Exception {
String contractA =
"contract A {" +
" bytes32 public blockHash;" +
" function a(){" +
" blockHash = block.blockhash(block.number - 1);" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract a = bc.submitNewContract(contractA);
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
Block b4 = bc.createBlock();
Block b5 = bc.createBlock();
Block b6 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
a.callFunction("a");
Block b3_ = bc.createForkBlock(b2_);
Object hash = a.callConstFunction(b3_, "blockHash")[0];
Assert.assertArrayEquals((byte[]) hash, b2_.getHash());
// no StackOverflowException
}
示例10: testOldBlockIncluded
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testOldBlockIncluded() 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();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
for (int i = 0; i < 16; i++) {
bc.createBlock();
}
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
bc.submitTransaction(tx1);
Block b18 = bc.createBlock();
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b18.getHash());
}
示例11: testTrackTx1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testTrackTx1() 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();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
pendingState.trackTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2_.getHash());
}
示例12: testTrackTx2
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testTrackTx2() 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();
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
pendingState.trackTransaction(tx1);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2.getHash());
Block b2_ = bc.createForkBlock(b1);
Block b3_ = bc.createForkBlock(b2_);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
}
示例13: createContractFork
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void createContractFork() throws Exception {
// #1 (Parent) --> #2 --> #3 (Child) ----------------------> #4 (call Child)
// \-------------------------------> #2' (forked Child)
//
// Testing the situation when the Child contract is created by the Parent contract
// first on the main chain with one parameter (#3) and then on the fork with another parameter (#2')
// so their storages are different. Check that original Child storage is not broken
// on the main chain (#4)
String contractSrc =
"contract Child {" +
" int a;" +
" int b;" +
" int public c;" +
" function Child(int i) {" +
" a = 333 + i;" +
" b = 444 + i;" +
" }" +
" function sum() {" +
" c = a + b;" +
" }" +
"}" +
"contract Parent {" +
" address public child;" +
" function createChild(int a) returns (address) {" +
" child = new Child(a);" +
" return child;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract parent = bc.submitNewContract(contractSrc, "Parent");
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
parent.callFunction("createChild", 100);
Block b3 = bc.createBlock();
byte[] childAddress = (byte[]) parent.callConstFunction("child")[0];
parent.callFunction("createChild", 200);
Block b2_ = bc.createForkBlock(b1);
SolidityContract child = bc.createExistingContractFromSrc(contractSrc, "Child", childAddress);
child.callFunction("sum");
Block b4 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(100 + 333 + 100 + 444), child.callConstFunction("c")[0]);
}
示例14: testRebranch1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testRebranch1() 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();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Transaction tx2 = bc.createTransaction(charlie, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);;
pendingState.addPendingTransaction(tx2);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx2), NEW_PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertEquals(l.pollTxUpdateState(tx2), PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx2);
Block b3 = bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
Block b2_ = bc.createForkBlock(b1);
Block b3_ = bc.createForkBlock(b2_);
bc.submitTransaction(tx2);
Block b4_ = bc.createForkBlock(b3_);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
Block b5_ = bc.createForkBlock(b4_);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
}
示例15: testRebranch3
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testRebranch3() 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();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3 = bc.createBlock();
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2_.getHash());
Block b4 = bc.createForkBlock(b3);
Block b5 = bc.createForkBlock(b4);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2.getHash());
}