我正在尝试为我正在编写的智能合约编写一些单元测试,但是在弄清楚如何在创建时将参数传递给我的合约的构造函数时遇到了困难。下面是我的代码:
const assert = require('assert');
const ganache = require('ganache-cli');
const provider = ganache.provider();
const Web3 = require('web3');
const web3 = new Web3(provider);
const { interface, bytecode } = require('../ethereum/compile');
let token;
let accounts;
beforeEach(async () => {
accounts = await web3.eth.getAccounts();
token = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode })
.send({ from: accounts[0], gas: '1000000' });
token.setProvider(provider);
});
describe('Token Contract', () => { ... });
Run Code Online (Sandbox Code Playgroud)
基于此设置,我如何将参数传递给合同?我通过学习 Solidity 课程做到了这一点,但是课程中的合同对其构造函数没有任何选择,因此它从未涵盖它们应该去哪里。感谢您的帮助!