Presentation link https://aka.ms/Trufflecon2018
Video recording https://www.youtube.com/watch?v=Auf8W5q1I9c
- I live in Australia (30 hour travel time to Trufflecon)
- Blockchain Domain lead @ Microsoft.
- CSE (Commercial Software Engineering), work with Microsoft's top 400 enterprises globally to help their dev teams be awesome on Azure.
- Been using Truffle since 2016, I created a lot of the early Truffle on Windows tutorials https://truffleframework.com/tutorials
Because some npm packages don't run nicely on windows (due to node-gyp), I recommend devs use Ubuntu on Windows.
- Installing Truffle on Ubuntu
- Use Hyper as a better terminal https://hyper.is/
- WSL Install guide
- WSL overview blog post
Demo: show that
screenfetch
&htop
work
Free. Open Source. Runs on Windows / Linux / Mac. Lots of plugins available.
Start with metacoin box as it has things nicely configured
truffle unbox metacoin
PAIN POINT: Truffle boxes missing licensing.
PAIN POINT:
truffle watch
does not work
Need to use a tool like nodemon
or chokidar-cli to watch and run tests.
npm install -g chokidar-cli
chokidar 'contracts/*.sol' 'test/*.js' -c 'truffle test' --initial
PAIN POINT: I want a common artifact format across Truffle & Nethereum. Load a
metacoin.json
file into Nethereum and have it auto detect the ABI & deployed address.
PAIN POINT: the sample tests are sync. Async tests are smaller and cleaner.
Change unit tests to async
Prerequisite: Install truffle as a dev dependency
npm init -y
npm install truffle --save-dev
Cloud-hosted pipelines for Linux, macOS, and Windows with unlimited minutes and 10 free parallel jobs for open source. https://azure.microsoft.com/en-us/services/devops/pipelines/
https://github.com/marketplace/azure-pipelines
# azure-pipelines.js - npm install, then run the tests
- script: |
npm install
displayName: 'npm install'
- script: |
npx truffle compile
npx truffle test
displayName: 'truffle compile & test'
# Install mocha & junit reporter, allowing output in JUnit XML
npm install truffle mocha mocha-junit-reporter --save-dev
// truffle.js - specify mocha output options
// set the reporter to "spec" to output to terminal, or "mocha-junit-reporter" to output XML
mocha: {
reporter: "spec",
reporterOptions: {
mochaFile: 'TEST-truffle.xml'
}
},
PAIN POINT: Need to change test runner manually. Can I pass a param into
truffle test
to change the test runner.
# azure-pipelines.js
# Insert this before running Truffle Test. This will set the reporter to output junit XML
- script: |
sed -i -e 's/reporter: "spec"/reporter: "mocha-junit-reporter"/g' truffle.js
displayName: 'configure mocha to output junit'
# Put this after running Truffle Test. Publishes Test Results in Azure DevOps
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/TEST-*.xml'
- modify metacoin.sol to break test
- check broken code on a branch and push
- create a pull request
npm install truffle-hdwallet-provider --save
PAIN POINT: requires node-gyp. Can we have this web packed like Truffle?
Note: don't put raw mnemonic in truffle.js, use pipeline variables to keep them secret
- https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups
- https://stackoverflow.com/questions/49578709/is-there-a-way-to-provide-environment-variables-to-a-vsts-ci-npm-task
// truffle.js
var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
var networkEndpoint = "http://eth5kzzgs-dns-reg1.westus.cloudapp.azure.com:8540";
// var mnemonic = process.env.deploymentMnemonic;
// var networkEndpoint = process.env.deploymentNetworkEndpoint;
module.exports = {
//...
networks: {
azure: {
provider: function () {
return new HDWalletProvider(mnemonic, networkEndpoint, 0)
},
gasPrice : 0,
network_id: "*"
}
}
//...
}
- script: |
npx truffle migrate --network azure
displayName: 'contract deployment'
PAIN POINT: Once migrations are run, where to store the artifacts? EthPM?