区块链测试环境搭建

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaoleizhanghahaha/article/details/83685767

1.从docker hub选择下载相关容器   https://hub.docker.com/search/

2.容器下载   docker pull ubuntu

3.容器加速  https://www.daocloud.io/mirror#accelerator-doc

4.进入容器安装环境
docker run -it ubuntu /bin/bash
cat /etc/issue

5.安装-新建用户和赋予ROOT权限

apt-get update
apt-get install vim
apt-get install sudo

adduser deploy

chmod 777 /etc/sudoers    可读可写可执行
vim /etc/sudoers    找到root  deploy   ALL=(ALL=ALL) ALL 保存退出

chmod 440 /etc/sudoers

su deploy

6.安装 nodejs truffle和testrpc

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

安装失败https://blog.csdn.net/xiaoleizhanghahaha/article/details/83715721

https://mirrors.tuna.tsinghua.edu.cn/help/nodesource/


sudo apt-get install nodejs
node –v
npm –v

npm install -g cnpm --registry=https://registry.npm.taobao.org
sudo cnpm install -g ethereumjs-testrpc

https://www.npmjs.com/package/ethereumjs-testrpc-persist

sudo cnpm install -g truffle
truffle version
https://www.npmjs.com/package/truffle

sudo apt-get install tree
docker commit

7.代码集成环境
.idea + solidty

8.docker 挂载本地目录
docker run -it -v /Users/xuxinlai/blockchain/ethereum:/home/deploy ec0a49148d7b /bin/bash

9.Demo

1.truffle init

2.代码:MyCoin.sol

pragma solidity ^0.4.17; contract MyCoin {     // getBalance     function getBalance() public pure returns(uint) {         return 1;     } }

3.代码:2_deploy_contracts.js

var MyCoin = artifacts.require("./MyCoin.sol"); module.exports = function(deployer) {   //add for demo   deployer.deploy(MyCoin); };

4.代码:TestMyCoin.sol

pragma solidity ^0.4.17; import "truffle/Assert.sol"; import "../contracts/MyCoin.sol"; contract TestMyCoin {     function testHelloWorld() public{         MyCoin instance = new MyCoin();         uint expected = 1;         Assert.equal(instance.getBalance(), expected, "Test OK");     } }

5.代码:truffle.js

module.exports = {     networks: {         development: {             host: "localhost",             port: 8545,             network_id: "123456" // 匹配任何network id         }     } };

truffle compile

6.testrpc &

7.truffle migrate

8.truffle test

9. docker save -o testrpc-truffle-demo.tar a63219c08e93

10. docker load -i testrpc-truffle-demo.tar

11. docker tag a63219c08e93 test-truffle-demo:v1

猜你喜欢

转载自blog.csdn.net/xiaoleizhanghahaha/article/details/83685767