如何在 Truffle 测试中调用成员函数?
How to call a members function in a Truffle test?
考虑以下设置:
contract A {
B public b = new B();
}
contract B {
function C() public pure returns (uint c)
{
c = 5;
}
}
从 Truffle 测试中,有一个 A 的实例,如何调用函数 C?
这里有一个关于如何在 Truffle 测试中调用 C 的例子:
const A = artifacts.require('A')
const B = artifacts.require('B')
contract('A', function(accounts) {
it('should be possible to call C', async function() {
let a = await A.new({from: accounts[0]})
let addressOfB = await a.b();
let contractB = web3.eth.contract(B.abi)
let b = contractB.at(addressOfB)
console.log("Output of C: " + await (b.C()).toNumber());
})
})
Contract: A
Output of C: 5
✓ should be possible to call C (380ms)
1 passing (400ms)
考虑以下设置:
contract A {
B public b = new B();
}
contract B {
function C() public pure returns (uint c)
{
c = 5;
}
}
从 Truffle 测试中,有一个 A 的实例,如何调用函数 C?
这里有一个关于如何在 Truffle 测试中调用 C 的例子:
const A = artifacts.require('A')
const B = artifacts.require('B')
contract('A', function(accounts) {
it('should be possible to call C', async function() {
let a = await A.new({from: accounts[0]})
let addressOfB = await a.b();
let contractB = web3.eth.contract(B.abi)
let b = contractB.at(addressOfB)
console.log("Output of C: " + await (b.C()).toNumber());
})
})
Contract: A
Output of C: 5
✓ should be possible to call C (380ms)
1 passing (400ms)