truffle测试步骤流程

1、安装Ganache

安装本地Ganache 进入官网:Ganache - Truffle SuiteQuickly fire up a personal Ethereum blockchain which you can use to run tests, execute commands, and inspect state while controlling how the chain operates.icon-default.png?t=O83Ahttps://trufflesuite.com/ganache/我们下载对应的电脑系统的版本,下载安装包后,直接安装即可

按照进入ganache有两个选项,点击NEW WORKAPACE新建

我们选择定制启动,可以配置我们的一个PORT NUMBET,NETWORK ID等等

2、部署

下载node.js 利用npm 下载truffle :

npm install -g truffle

(在vs code新建truffle项目)

 打开新建的项目,打开终端输入 truffle init

3、接下来我们来将下面的HelloWorld合约放到我们工程中的contracts中

pragma solidity ^0.5.2;

contract HelloWorld {  

string name;

event setEvent (

      string name

   );

constructor() public {      

name = "Hello, World!";

}

function get() public view returns (string memory) {

       return name;

   }

function set(string memory n) public {

       name = n;

       emit setEvent(n);

   }

}

4、编写部署脚本(多个迁移文件,开头必须加数字,表明迁移顺序) 

const HelloWorld = artifacts.require("HelloWorld");

module.exports = async function (deployer) {

    await deployer.deploy(HelloWorld);

    const h = await HelloWorld.deployed();

    console.log("部署第一脚本地址="+h.address);

}

5、修改truffle-config.js 配置, 下面的port对应也是本地Ganche的配置

6、修改truffle-config.js 配置对应合约的版本(注意:合约版本得对应,否则会出错)

7、在终端输入 truffle compile编译

8、在终端输入truffle migrate部署

9、部署好之后,就回去看ganache,如果TX COUNT变成了1,就说明成功了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值