本文整理汇总了Java中org.ethereum.util.blockchain.SolidityContract.callConstFunction方法的典型用法代码示例。如果您正苦于以下问题:Java SolidityContract.callConstFunction方法的具体用法?Java SolidityContract.callConstFunction怎么用?Java SolidityContract.callConstFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.util.blockchain.SolidityContract
的用法示例。
在下文中一共展示了SolidityContract.callConstFunction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeTest1
import org.ethereum.util.blockchain.SolidityContract; //导入方法依赖的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);
}
示例2: simpleDbTest
import org.ethereum.util.blockchain.SolidityContract; //导入方法依赖的package包/类
@Test
public void simpleDbTest() {
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract parent = bc.submitNewContract("contract A {" +
" uint public a;" +
" function set(uint a_) { a = a_;}" +
"}");
bc.createBlock();
parent.callFunction("set", 123);
bc.createBlock();
Object ret = parent.callConstFunction("a")[0];
System.out.println("Ret = " + ret);
}
示例3: prevBlockHashOnFork
import org.ethereum.util.blockchain.SolidityContract; //导入方法依赖的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
}
示例4: functionTypeTest
import org.ethereum.util.blockchain.SolidityContract; //导入方法依赖的package包/类
@Test
public void functionTypeTest() throws IOException, InterruptedException {
String contractA =
"contract A {" +
" int public res;" +
" function calc(int b, function (int a) external returns (int) f) external returns (int) {" +
" return f(b);" +
" }" +
" function fInc(int a) external returns (int) { return a + 1;}" +
" function fDec(int a) external returns (int) { return a - 1;}" +
" function test() {" +
" res = this.calc(111, this.fInc);" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract a = bc.submitNewContract(contractA);
bc.createBlock();
a.callFunction("test");
bc.createBlock();
Assert.assertEquals(a.callConstFunction("res")[0], BigInteger.valueOf(112));
BigInteger r1 = (BigInteger) a.callConstFunction("calc", 222, a.getFunction("fInc"))[0];
Assert.assertEquals(223, r1.intValue());
BigInteger r2 = (BigInteger) a.callConstFunction("calc", 222, a.getFunction("fDec"))[0];
Assert.assertEquals(221, r2.intValue());
}
示例5: createContractFork
import org.ethereum.util.blockchain.SolidityContract; //导入方法依赖的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]);
}