无忧中英繁企业网站系统 破解,从零开始学做网站,凡科网站免费版,手机网站怎么做沉浸式在windos终端内安装truffle
npm install -g truffle truffle --version 出现上图情况也没问题
下面就可以进行我们的操作了
创建一个文件truffle 创建一个空工程 truffle init 在contracts内加入HelloWorld合约
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
c…在windos终端内安装truffle
npm install -g truffle truffle --version 出现上图情况也没问题
下面就可以进行我们的操作了
创建一个文件truffle 创建一个空工程 truffle init 在contracts内加入HelloWorld合约
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HelloWorld {
string private greeting;
// 构造函数设置初始问候语
constructor() {greeting Hello World;
}// 获取当前的问候语
function get() public view returns (string memory) {return greeting;
}// 设置新的问候语
function set(string memory newGreeting) public {greeting newGreeting;
}} 在migration内编写迁移脚本
const HelloWorld artifacts.require(HelloWorld);module.exports async function (deployer) {// 部署 HelloWorld 合约await deployer.deploy(HelloWorld);
};
在test文件内添加测试脚本
const Helloworld artifacts.require(HelloWorld);
contract(HelloWorld, async() {let newData123;it(Test helloWorld get, async () {const hello await Helloworld.deployed();let name await hello.get();console.log(init data,name);assert.equal(name,Hello World,Test fail);});it(Test helloWorld set, async () {const hello await Helloworld.deployed();await hello.set(newData);});it(Test HelloWorld get2, async () {const hello await Helloworld.deployed();let name await hello.get();console.log(Updated data:, name); assert.equal(name,123,Test fail);});});
更改文件truffle-config.js 文件总览 开始正式测试测试的顺序为truffle develop(启用测试网络) compile(编译合约) migrate(部署合约) test(测试合约) 部署 truffle develop compile migrate 测试truffle test 测试成功别看流程这么简单中间解决好多报错用用一键三连学习更多查看我的其它博客