├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── build └── contracts │ ├── Migrations.json │ └── Users.json ├── config ├── eslint │ ├── .eslintignore │ └── .eslintrc.js ├── postcss │ └── postcss.config.js ├── vue-loader │ └── vue-loader.conf.js └── webpack │ ├── dev.env.js │ ├── index.js │ ├── prod.env.js │ └── test.env.js ├── contracts ├── Migrations.sol └── Users.sol ├── index.html ├── migrations ├── 1_initial_migration.js └── 2_deploy_contracts.js ├── package-lock.json ├── package.json ├── scripts ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── webpack.base.conf.js ├── webpack.dev.conf.js ├── webpack.prod.conf.js └── webpack.test.conf.js ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── Dashboard.vue │ └── Signup.vue ├── js │ └── users.js ├── main.js └── router │ └── index.js ├── static └── .gitkeep ├── test ├── e2e │ ├── custom-assertions │ │ └── elementCount.js │ ├── nightwatch.conf.js │ ├── runner.js │ └── specs │ │ └── test.js ├── truffle │ ├── TestUsers.sol │ └── user.js └── unit │ ├── .eslintrc │ ├── index.js │ ├── karma.conf.js │ └── specs │ └── Dashboard.spec.js ├── truffle-box.json └── truffle.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | test/unit/coverage 8 | test/e2e/reports 9 | selenium-debug.log 10 | 11 | # Editor directories and files 12 | .idea 13 | *.suo 14 | *.ntvs* 15 | *.njsproj 16 | *.sln 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 wespr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue.js truffle box 2 | 3 | A [`truffle box`](http://truffleframework.com/boxes/) to serve as the foundation of any [`Truffle`](http://truffleframework.com) and [`Vue.js`](https://vuejs.org/) dApp. Comes with [`Vue.js`](https://vuejs.org/), [`vue-router`](https://router.vuejs.org/en/), [`Vuex`](https://vuex.vuejs.org/en/intro.html) and [`sass-loader`](https://github.com/webpack-contrib/sass-loader). A minimalist user authentication smart contract is also provided. 4 | 5 | ## Directory structure 6 | 7 | This truffle box is crafted to enforce a clean directory structure. 8 | 9 | ``` 10 | / 11 | | 12 | +-- build/ 13 | | | 14 | | +-- contracts/ 15 | | | | 16 | | | + truffle compiled contracts 17 | | 18 | +-- config/ 19 | | | 20 | | +-- babel/ 21 | | | | 22 | | | + babel config files - to come (babel does not allow to specify a custom config file path - yet - so the babel configuration occurs in the package.json file for now) 23 | | | 24 | | +-- eslint/ 25 | | | | 26 | | | + estlint config files 27 | | | 28 | | +-- postcss/ 29 | | | | 30 | | | + postcss config files 31 | | | 32 | | +-- vue-loader 33 | | | | 34 | | | + vue-loader config files 35 | | | 36 | | +-- webpack/ 37 | | | | 38 | | | + webpack config files 39 | | 40 | +-- contracts/ 41 | | | 42 | | + solidity contracts 43 | | 44 | +-- migrations/ 45 | | | 46 | | + truffle migrations files 47 | | 48 | +-- scripts/ 49 | | | 50 | | + webpack scripts 51 | | 52 | +-- src/ 53 | | | 54 | | + vue.js dapp files 55 | | 56 | +-- static/ 57 | | | 58 | | + vue.js dapp static files 59 | | 60 | +-- test/ 61 | | | 62 | | +-- e2e/ 63 | | | | 64 | | | + e2e test files 65 | | | 66 | | +-- truffle/ 67 | | | | 68 | | | + truffle test files 69 | | | 70 | | +-- unit/ 71 | | | | 72 | | | + unit test files 73 | ``` 74 | 75 | ## Installation 76 | 77 | 1. Install [Truffle](http://truffleframework.com) and an Ethereum client - like [EthereumJS TestRPC](https://github.com/ethereumjs/testrpc). 78 | ``` 79 | npm install -g truffle // Version 3.0.5+ required. 80 | npm install -g ethereumjs-testrpc 81 | ``` 82 | 83 | 2. Download this box. 84 | ``` 85 | truffle unbox wespr/truffle-vue 86 | ``` 87 | 3. Launch [`testrpc`](https://github.com/ethereumjs/testrpc). 88 | ``` 89 | testrpc 90 | ``` 91 | 92 | 4. Compile and migrate the contracts. 93 | ``` 94 | truffle compile 95 | truffle migrate 96 | ``` 97 | 98 | 4. Run the webpack server for front-end hot reloading. Smart contract changes do not support hot reloading for now. 99 | ``` 100 | npm run start 101 | ``` 102 | 103 | ## Tests 104 | This box comes with everything bundled for `unit`, `e2e` and `truffle` contracts testing. 105 | 106 | 1. `unit` and `e2e` tests. 107 | ``` 108 | npm run test/dapp 109 | ``` 110 | 111 | 2. `truffle` contracts tests. 112 | ``` 113 | npm run test/truffle 114 | ``` 115 | 116 | 3. Alternatively you can directly run `unit`, `e2e` and `truffle` contracts tests in one command. 117 | ``` 118 | npm run test 119 | ``` 120 | 121 | ## Build for production 122 | To build the application for production, use the build command. A production build will be compiled in the `dist` folder. 123 | ```javascript 124 | npm run build 125 | ``` 126 | 127 | ## Issues 128 | 129 | Please send any bug issues or proposal for improvement to [Issues](https://github.com/wespr/truffle-vue/issues). -------------------------------------------------------------------------------- /build/contracts/Migrations.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "Migrations", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [ 7 | { 8 | "name": "new_address", 9 | "type": "address" 10 | } 11 | ], 12 | "name": "upgrade", 13 | "outputs": [], 14 | "payable": false, 15 | "type": "function" 16 | }, 17 | { 18 | "constant": true, 19 | "inputs": [], 20 | "name": "last_completed_migration", 21 | "outputs": [ 22 | { 23 | "name": "", 24 | "type": "uint256" 25 | } 26 | ], 27 | "payable": false, 28 | "type": "function" 29 | }, 30 | { 31 | "constant": true, 32 | "inputs": [], 33 | "name": "owner", 34 | "outputs": [ 35 | { 36 | "name": "", 37 | "type": "address" 38 | } 39 | ], 40 | "payable": false, 41 | "type": "function" 42 | }, 43 | { 44 | "constant": false, 45 | "inputs": [ 46 | { 47 | "name": "completed", 48 | "type": "uint256" 49 | } 50 | ], 51 | "name": "setCompleted", 52 | "outputs": [], 53 | "payable": false, 54 | "type": "function" 55 | }, 56 | { 57 | "inputs": [], 58 | "payable": false, 59 | "type": "constructor" 60 | } 61 | ], 62 | "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a72305820a0f0320799e8fc6ecc0610f333ca4b6e6f81a639b55333de0dd844534d6df3730029", 63 | "networks": { 64 | "5": { 65 | "events": {}, 66 | "links": {}, 67 | "address": "0x563d56934e2a088fb462865317b0a2b5c20a6fb3", 68 | "updated_at": 1507567141706 69 | } 70 | }, 71 | "schema_version": "0.0.5", 72 | "updated_at": 1507567141706 73 | } -------------------------------------------------------------------------------- /build/contracts/Users.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "Users", 3 | "abi": [ 4 | { 5 | "constant": true, 6 | "inputs": [], 7 | "name": "authenticate", 8 | "outputs": [ 9 | { 10 | "name": "_pseudo", 11 | "type": "bytes32" 12 | } 13 | ], 14 | "payable": false, 15 | "type": "function" 16 | }, 17 | { 18 | "constant": false, 19 | "inputs": [ 20 | { 21 | "name": "_hash", 22 | "type": "bytes32" 23 | } 24 | ], 25 | "name": "create", 26 | "outputs": [], 27 | "payable": false, 28 | "type": "function" 29 | }, 30 | { 31 | "constant": false, 32 | "inputs": [], 33 | "name": "destroy", 34 | "outputs": [], 35 | "payable": false, 36 | "type": "function" 37 | }, 38 | { 39 | "constant": true, 40 | "inputs": [ 41 | { 42 | "name": "_address", 43 | "type": "address" 44 | } 45 | ], 46 | "name": "get", 47 | "outputs": [ 48 | { 49 | "name": "_pseudo", 50 | "type": "bytes32" 51 | } 52 | ], 53 | "payable": false, 54 | "type": "function" 55 | }, 56 | { 57 | "constant": true, 58 | "inputs": [ 59 | { 60 | "name": "_address", 61 | "type": "address" 62 | } 63 | ], 64 | "name": "exists", 65 | "outputs": [ 66 | { 67 | "name": "_exists", 68 | "type": "bool" 69 | } 70 | ], 71 | "payable": false, 72 | "type": "function" 73 | }, 74 | { 75 | "anonymous": false, 76 | "inputs": [ 77 | { 78 | "indexed": true, 79 | "name": "_address", 80 | "type": "address" 81 | }, 82 | { 83 | "indexed": false, 84 | "name": "_pseudo", 85 | "type": "bytes32" 86 | } 87 | ], 88 | "name": "UserCreated", 89 | "type": "event" 90 | }, 91 | { 92 | "anonymous": false, 93 | "inputs": [ 94 | { 95 | "indexed": true, 96 | "name": "_address", 97 | "type": "address" 98 | }, 99 | { 100 | "indexed": false, 101 | "name": "_pseudo", 102 | "type": "bytes32" 103 | } 104 | ], 105 | "name": "UserUpdated", 106 | "type": "event" 107 | }, 108 | { 109 | "anonymous": false, 110 | "inputs": [ 111 | { 112 | "indexed": true, 113 | "name": "_address", 114 | "type": "address" 115 | } 116 | ], 117 | "name": "UserDestroyed", 118 | "type": "event" 119 | } 120 | ], 121 | "unlinked_binary": "0x6060604052341561000f57600080fd5b5b61028f8061001f6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663380c7a6781146100695780637368a8ce1461008e57806383197ef0146100a6578063c2bc2efc146100bb578063f6a3d24e146100ec575b600080fd5b341561007457600080fd5b61007c61011f565b60405190815260200160405180910390f35b341561009957600080fd5b6100a4600435610153565b005b34156100b157600080fd5b6100a46101ad565b005b34156100c657600080fd5b61007c600160a060020a036004351661020c565b60405190815260200160405180910390f35b34156100f757600080fd5b61010b600160a060020a0360043516610242565b604051901515815260200160405180910390f35b600061012a33610242565b151561013557600080fd5b50600160a060020a0333166000908152602081905260409020545b90565b600160a060020a033381166000908152602081905260409081902083905530909116907f18ec7dd8c4d713eb3c2e0c61825f878a47e207600626611c5bc15009c743b4b69083905190815260200160405180910390a25b50565b6101b633610242565b15156101c157600080fd5b600160a060020a033316600081815260208190526040808220919091557f36539d9970f057e4d26f828835b69fcfff15ff997f804dace8aed405cb98455f905160405180910390a25b565b600061021782610242565b151561022257600080fd5b50600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a03811660009081526020819052604090205415155b9190505600a165627a7a72305820dbf7fd1a14899ad70ff91b5930a238f3559a7d8f1ae65998025da4e6e13883470029", 122 | "networks": { 123 | "5": { 124 | "events": { 125 | "0x18ec7dd8c4d713eb3c2e0c61825f878a47e207600626611c5bc15009c743b4b6": { 126 | "anonymous": false, 127 | "inputs": [ 128 | { 129 | "indexed": true, 130 | "name": "_address", 131 | "type": "address" 132 | }, 133 | { 134 | "indexed": false, 135 | "name": "_pseudo", 136 | "type": "bytes32" 137 | } 138 | ], 139 | "name": "UserCreated", 140 | "type": "event" 141 | }, 142 | "0x6c46eb453c5219d7665e4dda98f6200b9c6978d989806dfc2d2b17dc03609c53": { 143 | "anonymous": false, 144 | "inputs": [ 145 | { 146 | "indexed": true, 147 | "name": "_address", 148 | "type": "address" 149 | }, 150 | { 151 | "indexed": false, 152 | "name": "_pseudo", 153 | "type": "bytes32" 154 | } 155 | ], 156 | "name": "UserUpdated", 157 | "type": "event" 158 | }, 159 | "0x36539d9970f057e4d26f828835b69fcfff15ff997f804dace8aed405cb98455f": { 160 | "anonymous": false, 161 | "inputs": [ 162 | { 163 | "indexed": true, 164 | "name": "_address", 165 | "type": "address" 166 | } 167 | ], 168 | "name": "UserDestroyed", 169 | "type": "event" 170 | } 171 | }, 172 | "links": {}, 173 | "address": "0x46260d8d21d2912adafa8deae6f05a1cfe2ee890", 174 | "updated_at": 1507567141698 175 | } 176 | }, 177 | "schema_version": "0.0.5", 178 | "updated_at": 1507567141698 179 | } -------------------------------------------------------------------------------- /config/eslint/.eslintignore: -------------------------------------------------------------------------------- 1 | ../build/*.js 2 | ./*.js 3 | -------------------------------------------------------------------------------- /config/eslint/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md 13 | extends: 'standard', 14 | // required to lint *.vue files 15 | plugins: [ 16 | 'html' 17 | ], 18 | // add your custom rules here 19 | 'rules': { 20 | // allow paren-less arrow functions 21 | 'arrow-parens': 0, 22 | // allow async-await 23 | 'generator-star-spacing': 0, 24 | // allow debugger during development 25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /config/postcss/postcss.config.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": [ 5 | // to edit target browsers: use "browserslist" field in package.json 6 | require('autoprefixer')() 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /config/vue-loader/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('../../scripts/utils') 3 | var config = require('../webpack') 4 | var postcssPlugins = require('../postcss/postcss.config.js').plugins 5 | var isProduction = process.env.NODE_ENV === 'production' 6 | 7 | module.exports = { 8 | loaders: utils.cssLoaders({ 9 | sourceMap: isProduction 10 | ? config.build.productionSourceMap 11 | : config.dev.cssSourceMap, 12 | extract: isProduction 13 | }), 14 | transformToRequire: { 15 | video: 'src', 16 | source: 'src', 17 | img: 'src', 18 | image: 'xlink:href' 19 | }, 20 | postcss: { 21 | plugins: postcssPlugins 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /config/webpack/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/webpack/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/webpack/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /config/webpack/test.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var devEnv = require('./dev.env') 3 | 4 | module.exports = merge(devEnv, { 5 | NODE_ENV: '"testing"' 6 | }) 7 | -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/Users.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.15; 2 | 3 | contract Users { 4 | 5 | mapping(address => bytes32) public users; 6 | 7 | event UserCreated(address indexed _address, bytes32 _pseudo); 8 | event UserDestroyed(address indexed _address); 9 | 10 | function exists (address _address) public constant returns (bool _exists) { 11 | return (users[_address] != bytes32(0)); 12 | } 13 | 14 | function authenticate () public constant returns (bytes32 _pseudo) { 15 | require(exists(msg.sender)); 16 | return (users[msg.sender]); 17 | } 18 | 19 | function create (bytes32 _pseudo) public { 20 | users[msg.sender] = _pseudo ; 21 | UserCreated(msg.sender, _pseudo); 22 | } 23 | 24 | function destroy () public { 25 | require(exists(msg.sender)); 26 | delete users[msg.sender]; 27 | UserDestroyed(msg.sender); 28 | } 29 | 30 | function get (address _address) public constant returns(bytes32 _pseudo) { 31 | require(exists(_address)); 32 | return (users[_address]); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | truffle-vue 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var Users = artifacts.require("./Users.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Users); 5 | }; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "truffle-vue", 3 | "version": "0.2.0", 4 | "description": "A vue.js truffle box", 5 | "author": "osarrouy ", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node scripts/dev-server.js", 9 | "start": "npm run dev", 10 | "build": "node scripts/build.js", 11 | "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", 12 | "e2e": "node test/e2e/runner.js", 13 | "test/truffle": "truffle test test/truffle/*", 14 | "test/dapp": "npm run unit && npm run e2e", 15 | "test": "npm run test/truffle && npm run test/dapp", 16 | "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" 17 | }, 18 | "dependencies": { 19 | "truffle-contract": "^3.0.0", 20 | "vue": "^2.4.2", 21 | "vue-router": "^2.7.0" 22 | }, 23 | "devDependencies": { 24 | "autoprefixer": "^7.1.2", 25 | "babel-core": "^6.22.1", 26 | "babel-eslint": "^7.1.1", 27 | "babel-loader": "^7.1.1", 28 | "babel-plugin-istanbul": "^4.1.1", 29 | "babel-plugin-transform-runtime": "^6.22.0", 30 | "babel-preset-env": "^1.3.2", 31 | "babel-preset-stage-2": "^6.22.0", 32 | "babel-register": "^6.22.0", 33 | "chai": "^3.5.0", 34 | "chalk": "^2.0.1", 35 | "chromedriver": "^2.27.2", 36 | "connect-history-api-fallback": "^1.3.0", 37 | "copy-webpack-plugin": "^4.0.1", 38 | "cross-env": "^5.0.1", 39 | "cross-spawn": "^5.0.1", 40 | "css-loader": "^0.28.0", 41 | "cssnano": "^3.10.0", 42 | "eslint": "^3.19.0", 43 | "eslint-config-standard": "^6.2.1", 44 | "eslint-friendly-formatter": "^3.0.0", 45 | "eslint-loader": "^1.7.1", 46 | "eslint-plugin-html": "^3.0.0", 47 | "eslint-plugin-promise": "^3.4.0", 48 | "eslint-plugin-standard": "^2.0.1", 49 | "eventsource-polyfill": "^0.9.6", 50 | "express": "^4.14.1", 51 | "extract-text-webpack-plugin": "^2.0.0", 52 | "file-loader": "^0.11.1", 53 | "friendly-errors-webpack-plugin": "^1.1.3", 54 | "html-webpack-plugin": "^2.28.0", 55 | "http-proxy-middleware": "^0.17.3", 56 | "inject-loader": "^3.0.0", 57 | "karma": "^1.4.1", 58 | "karma-coverage": "^1.1.1", 59 | "karma-mocha": "^1.3.0", 60 | "karma-phantomjs-launcher": "^1.0.2", 61 | "karma-phantomjs-shim": "^1.4.0", 62 | "karma-sinon-chai": "^1.3.1", 63 | "karma-sourcemap-loader": "^0.3.7", 64 | "karma-spec-reporter": "0.0.31", 65 | "karma-webpack": "^2.0.2", 66 | "mocha": "^3.2.0", 67 | "nightwatch": "^0.9.12", 68 | "node-sass": "^4.5.3", 69 | "opn": "^5.1.0", 70 | "optimize-css-assets-webpack-plugin": "^2.0.0", 71 | "ora": "^1.2.0", 72 | "phantomjs-prebuilt": "^2.1.14", 73 | "rimraf": "^2.6.0", 74 | "sass-loader": "^6.0.6", 75 | "selenium-server": "^3.0.1", 76 | "semver": "^5.3.0", 77 | "shelljs": "^0.7.6", 78 | "sinon": "^2.1.0", 79 | "sinon-chai": "^2.8.0", 80 | "url-loader": "^0.5.8", 81 | "vue-loader": "^13.0.4", 82 | "vue-style-loader": "^3.0.1", 83 | "vue-template-compiler": "^2.4.2", 84 | "webpack": "^2.6.1", 85 | "webpack-bundle-analyzer": "^2.2.1", 86 | "webpack-dev-middleware": "^1.10.0", 87 | "webpack-hot-middleware": "^2.18.0", 88 | "webpack-merge": "^4.1.0" 89 | }, 90 | "engines": { 91 | "node": ">= 4.0.0", 92 | "npm": ">= 3.0.0" 93 | }, 94 | "browserslist": [ 95 | "> 1%", 96 | "last 2 versions", 97 | "not ie <= 8" 98 | ], 99 | "babel": { 100 | "presets": [ 101 | [ 102 | "env", 103 | { 104 | "modules": false, 105 | "targets": { 106 | "browsers": [ 107 | "> 1%", 108 | "last 2 versions", 109 | "not ie <= 8" 110 | ] 111 | } 112 | } 113 | ], 114 | "stage-2" 115 | ], 116 | "plugins": [ 117 | "transform-runtime" 118 | ], 119 | "env": { 120 | "test": { 121 | "presets": [ 122 | "env", 123 | "stage-2" 124 | ], 125 | "plugins": [ 126 | "istanbul" 127 | ] 128 | } 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config/webpack') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | if (stats.hasErrors()) { 30 | console.log(chalk.red(' Build failed with errors.\n')) 31 | process.exit(1) 32 | } 33 | 34 | console.log(chalk.cyan(' Build complete.\n')) 35 | console.log(chalk.yellow( 36 | ' Tip: built files are meant to be served over an HTTP server.\n' + 37 | ' Opening index.html over file:// won\'t work.\n' 38 | )) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /scripts/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | var shell = require('shelljs') 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | } 15 | ] 16 | 17 | if (shell.which('npm')) { 18 | versionRequirements.push({ 19 | name: 'npm', 20 | currentVersion: exec('npm --version'), 21 | versionRequirement: packageConfig.engines.npm 22 | }) 23 | } 24 | 25 | module.exports = function () { 26 | var warnings = [] 27 | for (var i = 0; i < versionRequirements.length; i++) { 28 | var mod = versionRequirements[i] 29 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 30 | warnings.push(mod.name + ': ' + 31 | chalk.red(mod.currentVersion) + ' should be ' + 32 | chalk.green(mod.versionRequirement) 33 | ) 34 | } 35 | } 36 | 37 | if (warnings.length) { 38 | console.log('') 39 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 40 | console.log() 41 | for (var i = 0; i < warnings.length; i++) { 42 | var warning = warnings[i] 43 | console.log(' ' + warning) 44 | } 45 | console.log() 46 | process.exit(1) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /scripts/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /scripts/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config/webpack') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production') 14 | ? require('./webpack.prod.conf') 15 | : require('./webpack.dev.conf') 16 | 17 | // default port where dev server listens for incoming traffic 18 | var port = process.env.PORT || config.dev.port 19 | // automatically open browser, if not set will be false 20 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 21 | // Define HTTP proxies to your custom API backend 22 | // https://github.com/chimurai/http-proxy-middleware 23 | var proxyTable = config.dev.proxyTable 24 | 25 | var app = express() 26 | var compiler = webpack(webpackConfig) 27 | 28 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 29 | publicPath: webpackConfig.output.publicPath, 30 | quiet: true 31 | }) 32 | 33 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 34 | log: false, 35 | heartbeat: 2000 36 | }) 37 | // force page reload when html-webpack-plugin template changes 38 | compiler.plugin('compilation', function (compilation) { 39 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 40 | hotMiddleware.publish({ action: 'reload' }) 41 | cb() 42 | }) 43 | }) 44 | 45 | // proxy api requests 46 | Object.keys(proxyTable).forEach(function (context) { 47 | var options = proxyTable[context] 48 | if (typeof options === 'string') { 49 | options = { target: options } 50 | } 51 | app.use(proxyMiddleware(options.filter || context, options)) 52 | }) 53 | 54 | // handle fallback for HTML5 history API 55 | app.use(require('connect-history-api-fallback')()) 56 | 57 | // serve webpack bundle output 58 | app.use(devMiddleware) 59 | 60 | // enable hot-reload and state-preserving 61 | // compilation error display 62 | app.use(hotMiddleware) 63 | 64 | // serve pure static assets 65 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 66 | app.use(staticPath, express.static('./static')) 67 | 68 | var uri = 'http://localhost:' + port 69 | 70 | var _resolve 71 | var readyPromise = new Promise(resolve => { 72 | _resolve = resolve 73 | }) 74 | 75 | console.log('> Starting dev server...') 76 | devMiddleware.waitUntilValid(() => { 77 | console.log('> Listening at ' + uri + '\n') 78 | // when env is testing, don't need open it 79 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 80 | opn(uri) 81 | } 82 | _resolve() 83 | }) 84 | 85 | var server = app.listen(port) 86 | 87 | module.exports = { 88 | ready: readyPromise, 89 | close: () => { 90 | server.close() 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /scripts/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config/webpack') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /scripts/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config/webpack') 4 | var vueLoaderConfig = require('../config/vue-loader/vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './src/main.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('src'), 26 | '@config' : resolve('config'), 27 | '@contracts' : resolve('build/contracts') 28 | } 29 | }, 30 | module: { 31 | rules: [ 32 | { 33 | test: /\.(js|vue)$/, 34 | loader: 'eslint-loader', 35 | enforce: 'pre', 36 | include: [resolve('src'), resolve('test')], 37 | options: { 38 | formatter: require('eslint-friendly-formatter'), 39 | configFile: resolve('config/eslint/.eslintrc.js'), 40 | ignorePath: resolve('config/eslint/.eslintignore') 41 | } 42 | }, 43 | { 44 | test: /\.vue$/, 45 | loader: 'vue-loader', 46 | options: vueLoaderConfig 47 | }, 48 | { 49 | test: /\.js$/, 50 | loader: 'babel-loader', 51 | include: [resolve('src'), resolve('test')] 52 | }, 53 | { 54 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 55 | loader: 'url-loader', 56 | options: { 57 | limit: 10000, 58 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 59 | } 60 | }, 61 | { 62 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 63 | loader: 'url-loader', 64 | options: { 65 | limit: 10000, 66 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 67 | } 68 | }, 69 | { 70 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 71 | loader: 'url-loader', 72 | options: { 73 | limit: 10000, 74 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 75 | } 76 | } 77 | ] 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /scripts/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config/webpack') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./scripts/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }), 33 | new FriendlyErrorsPlugin() 34 | ] 35 | }) 36 | -------------------------------------------------------------------------------- /scripts/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config/webpack') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = process.env.NODE_ENV === 'testing' 13 | ? require('../config/webpack/test.env') 14 | : config.build.env 15 | 16 | var webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true 21 | }) 22 | }, 23 | devtool: config.build.productionSourceMap ? '#source-map' : false, 24 | output: { 25 | path: config.build.assetsRoot, 26 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 27 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 28 | }, 29 | plugins: [ 30 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 31 | new webpack.DefinePlugin({ 32 | 'process.env': env 33 | }), 34 | new webpack.optimize.UglifyJsPlugin({ 35 | compress: { 36 | warnings: false 37 | }, 38 | sourceMap: true 39 | }), 40 | // extract css into its own file 41 | new ExtractTextPlugin({ 42 | filename: utils.assetsPath('css/[name].[contenthash].css') 43 | }), 44 | // Compress extracted CSS. We are using this plugin so that possible 45 | // duplicated CSS from different components can be deduped. 46 | new OptimizeCSSPlugin({ 47 | cssProcessorOptions: { 48 | safe: true 49 | } 50 | }), 51 | // generate dist index.html with correct asset hash for caching. 52 | // you can customize output by editing /index.html 53 | // see https://github.com/ampedandwired/html-webpack-plugin 54 | new HtmlWebpackPlugin({ 55 | filename: process.env.NODE_ENV === 'testing' 56 | ? 'index.html' 57 | : config.build.index, 58 | template: 'index.html', 59 | inject: true, 60 | minify: { 61 | removeComments: true, 62 | collapseWhitespace: true, 63 | removeAttributeQuotes: true 64 | // more options: 65 | // https://github.com/kangax/html-minifier#options-quick-reference 66 | }, 67 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 68 | chunksSortMode: 'dependency' 69 | }), 70 | // keep module.id stable when vender modules does not change 71 | new webpack.HashedModuleIdsPlugin(), 72 | // split vendor js into its own file 73 | new webpack.optimize.CommonsChunkPlugin({ 74 | name: 'vendor', 75 | minChunks: function (module, count) { 76 | // any required modules inside node_modules are extracted to vendor 77 | return ( 78 | module.resource && 79 | /\.js$/.test(module.resource) && 80 | module.resource.indexOf( 81 | path.join(__dirname, '../node_modules') 82 | ) === 0 83 | ) 84 | } 85 | }), 86 | // extract webpack runtime and module manifest to its own file in order to 87 | // prevent vendor hash from being updated whenever app bundle is updated 88 | new webpack.optimize.CommonsChunkPlugin({ 89 | name: 'manifest', 90 | chunks: ['vendor'] 91 | }), 92 | // copy custom static assets 93 | new CopyWebpackPlugin([ 94 | { 95 | from: path.resolve(__dirname, '../static'), 96 | to: config.build.assetsSubDirectory, 97 | ignore: ['.*'] 98 | } 99 | ]) 100 | ] 101 | }) 102 | 103 | if (config.build.productionGzip) { 104 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 105 | 106 | webpackConfig.plugins.push( 107 | new CompressionWebpackPlugin({ 108 | asset: '[path].gz[query]', 109 | algorithm: 'gzip', 110 | test: new RegExp( 111 | '\\.(' + 112 | config.build.productionGzipExtensions.join('|') + 113 | ')$' 114 | ), 115 | threshold: 10240, 116 | minRatio: 0.8 117 | }) 118 | ) 119 | } 120 | 121 | if (config.build.bundleAnalyzerReport) { 122 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 123 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 124 | } 125 | 126 | module.exports = webpackConfig 127 | -------------------------------------------------------------------------------- /scripts/webpack.test.conf.js: -------------------------------------------------------------------------------- 1 | // This is the webpack config used for unit tests. 2 | 3 | var utils = require('./utils') 4 | var webpack = require('webpack') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | 8 | var webpackConfig = merge(baseWebpackConfig, { 9 | // use inline sourcemap for karma-sourcemap-loader 10 | module: { 11 | rules: utils.styleLoaders() 12 | }, 13 | devtool: '#inline-source-map', 14 | resolveLoader: { 15 | alias: { 16 | // necessary to to make lang="scss" work in test when using vue-loader's ?inject option 17 | // see discussion at https://github.com/vuejs/vue-loader/issues/724 18 | 'scss-loader': 'sass-loader' 19 | } 20 | }, 21 | plugins: [ 22 | new webpack.DefinePlugin({ 23 | 'process.env': require('../config/webpack/test.env') 24 | }) 25 | ] 26 | }) 27 | 28 | // no need for app entry during tests 29 | delete webpackConfig.entry 30 | 31 | module.exports = webpackConfig 32 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 24 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandonetwork/truffle-vue/35da64ca1d361f300b6a11fb5de12658fa38ca93/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/Dashboard.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 52 | 53 | 54 | 74 | -------------------------------------------------------------------------------- /src/components/Signup.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 44 | 45 | 75 | -------------------------------------------------------------------------------- /src/js/users.js: -------------------------------------------------------------------------------- 1 | import contract from 'truffle-contract' 2 | import UsersContract from '@contracts/Users.json' 3 | 4 | const Users = { 5 | 6 | contract: null, 7 | 8 | instance: null, 9 | 10 | init: function () { 11 | let self = this 12 | 13 | return new Promise(function (resolve, reject) { 14 | self.contract = contract(UsersContract) 15 | self.contract.setProvider(window.web3.currentProvider) 16 | 17 | self.contract.deployed().then(instance => { 18 | self.instance = instance 19 | resolve() 20 | }).catch(err => { 21 | reject(err) 22 | }) 23 | }) 24 | }, 25 | 26 | exists: function (address) { 27 | let self = this 28 | 29 | return new Promise((resolve, reject) => { 30 | self.instance.exists.call( 31 | address || window.web3.eth.defaultAccount, 32 | {from: window.web3.eth.accounts[0]} 33 | ).then(exists => { 34 | resolve(exists) 35 | }).catch(err => { 36 | reject(err) 37 | }) 38 | }) 39 | }, 40 | 41 | authenticate: function () { 42 | let self = this 43 | 44 | return new Promise((resolve, reject) => { 45 | self.instance.authenticate.call( 46 | {from: window.web3.eth.accounts[0]} 47 | ).then(pseudo => { 48 | resolve(window.web3.toUtf8(pseudo)) 49 | }).catch(err => { 50 | reject(err) 51 | }) 52 | }) 53 | }, 54 | 55 | create: function (pseudo) { 56 | let self = this 57 | 58 | return new Promise((resolve, reject) => { 59 | self.instance.create( 60 | pseudo, 61 | {from: window.web3.eth.accounts[0]} 62 | ).then(tx => { 63 | resolve(tx) 64 | }).catch(err => { 65 | reject(err) 66 | }) 67 | }) 68 | }, 69 | 70 | destroy: function () { 71 | let self = this 72 | 73 | return new Promise((resolve, reject) => { 74 | self.instance.destroy( 75 | {from: window.web3.eth.accounts[0]} 76 | ).then(tx => { 77 | resolve(tx) 78 | }).catch(err => { 79 | reject(err) 80 | }) 81 | }) 82 | } 83 | } 84 | 85 | export default Users 86 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import App from './App' 5 | import Web3 from 'web3' 6 | import router from './router' 7 | 8 | Vue.config.productionTip = false 9 | 10 | window.addEventListener('load', function () { 11 | if (typeof web3 !== 'undefined') { 12 | console.log('Web3 injected browser: OK.') 13 | window.web3 = new Web3(window.web3.currentProvider) 14 | } else { 15 | console.log('Web3 injected browser: Fail. You should consider trying MetaMask.') 16 | // fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail) 17 | window.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) 18 | } 19 | 20 | /* eslint-disable no-new */ 21 | new Vue({ 22 | el: '#app', 23 | router, 24 | template: '', 25 | components: { App } 26 | }) 27 | }) 28 | 29 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import Dashboard from '@/components/Dashboard' 4 | import Signup from '@/components/Signup' 5 | 6 | Vue.use(Router) 7 | 8 | export default new Router({ 9 | routes: [ 10 | { 11 | path: '/', 12 | name: 'dashboard', 13 | component: Dashboard 14 | }, 15 | { 16 | path: '/signup', 17 | name: 'signup', 18 | component: Signup 19 | } 20 | ] 21 | }) 22 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandonetwork/truffle-vue/35da64ca1d361f300b6a11fb5de12658fa38ca93/static/.gitkeep -------------------------------------------------------------------------------- /test/e2e/custom-assertions/elementCount.js: -------------------------------------------------------------------------------- 1 | // A custom Nightwatch assertion. 2 | // the name of the method is the filename. 3 | // can be used in tests like this: 4 | // 5 | // browser.assert.elementCount(selector, count) 6 | // 7 | // for how to write custom assertions see 8 | // http://nightwatchjs.org/guide#writing-custom-assertions 9 | exports.assertion = function (selector, count) { 10 | this.message = 'Testing if element <' + selector + '> has count: ' + count 11 | this.expected = count 12 | this.pass = function (val) { 13 | return val === this.expected 14 | } 15 | this.value = function (res) { 16 | return res.value 17 | } 18 | this.command = function (cb) { 19 | var self = this 20 | return this.api.execute(function (selector) { 21 | return document.querySelectorAll(selector).length 22 | }, [selector], function (res) { 23 | cb.call(self, res) 24 | }) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/e2e/nightwatch.conf.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | var config = require('../../config/webpack') 3 | 4 | // http://nightwatchjs.org/gettingstarted#settings-file 5 | module.exports = { 6 | src_folders: ['test/e2e/specs'], 7 | output_folder: 'test/e2e/reports', 8 | custom_assertions_path: ['test/e2e/custom-assertions'], 9 | 10 | selenium: { 11 | start_process: true, 12 | server_path: require('selenium-server').path, 13 | host: '127.0.0.1', 14 | port: 4444, 15 | cli_args: { 16 | 'webdriver.chrome.driver': require('chromedriver').path 17 | } 18 | }, 19 | 20 | test_settings: { 21 | default: { 22 | selenium_port: 4444, 23 | selenium_host: 'localhost', 24 | silent: true, 25 | globals: { 26 | devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) 27 | } 28 | }, 29 | 30 | chrome: { 31 | desiredCapabilities: { 32 | browserName: 'chrome', 33 | javascriptEnabled: true, 34 | acceptSslCerts: true 35 | } 36 | }, 37 | 38 | firefox: { 39 | desiredCapabilities: { 40 | browserName: 'firefox', 41 | javascriptEnabled: true, 42 | acceptSslCerts: true 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/e2e/runner.js: -------------------------------------------------------------------------------- 1 | // 1. start the dev server using production config 2 | process.env.NODE_ENV = 'testing' 3 | var server = require('../../scripts/dev-server.js') 4 | 5 | server.ready.then(() => { 6 | // 2. run the nightwatch test suite against it 7 | // to run in additional browsers: 8 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 9 | // 2. add it to the --env flag below 10 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 11 | // For more information on Nightwatch's config file, see 12 | // http://nightwatchjs.org/guide#settings-file 13 | var opts = process.argv.slice(2) 14 | if (opts.indexOf('--config') === -1) { 15 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) 16 | } 17 | if (opts.indexOf('--env') === -1) { 18 | opts = opts.concat(['--env', 'chrome']) 19 | } 20 | 21 | var spawn = require('cross-spawn') 22 | var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) 23 | 24 | runner.on('exit', function (code) { 25 | server.close() 26 | process.exit(code) 27 | }) 28 | 29 | runner.on('error', function (err) { 30 | server.close() 31 | throw err 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /test/e2e/specs/test.js: -------------------------------------------------------------------------------- 1 | // For authoring Nightwatch tests, see 2 | // http://nightwatchjs.org/guide#usage 3 | 4 | module.exports = { 5 | 'default e2e tests': function (browser) { 6 | // automatically uses dev Server port from /config.index.js 7 | // default: http://localhost:8080 8 | // see nightwatch.conf.js 9 | const devServer = browser.globals.devServerURL 10 | 11 | browser 12 | .url(devServer) 13 | .waitForElementVisible('#app', 5000) 14 | .assert.elementPresent('.dashboard') 15 | .assert.containsText('h1', 'Welcome to your truffle-vue dApp') 16 | .assert.elementCount('img', 1) 17 | .end() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/truffle/TestUsers.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.15; 2 | 3 | import "truffle/Assert.sol"; 4 | import "truffle/DeployedAddresses.sol"; 5 | import "../../contracts/Users.sol"; 6 | 7 | contract TestUsers { 8 | 9 | function testUser() { 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /test/truffle/user.js: -------------------------------------------------------------------------------- 1 | var Users = artifacts.require("./Users.sol"); 2 | 3 | contract('User', function(accounts) { 4 | }); 5 | -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true, 7 | "sinon": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/unit/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | Vue.config.productionTip = false 4 | 5 | // require all test files (files that ends with .spec.js) 6 | const testsContext = require.context('./specs', true, /\.spec$/) 7 | testsContext.keys().forEach(testsContext) 8 | 9 | // require all src files except main.js for coverage. 10 | // you can also change this to match only the subset of files that 11 | // you want coverage for. 12 | const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) 13 | srcContext.keys().forEach(srcContext) 14 | -------------------------------------------------------------------------------- /test/unit/karma.conf.js: -------------------------------------------------------------------------------- 1 | // This is a karma config file. For more details see 2 | // http://karma-runner.github.io/0.13/config/configuration-file.html 3 | // we are also using it with karma-webpack 4 | // https://github.com/webpack/karma-webpack 5 | 6 | var webpackConfig = require('../../scripts/webpack.test.conf') 7 | 8 | module.exports = function (config) { 9 | config.set({ 10 | // to run in additional browsers: 11 | // 1. install corresponding karma launcher 12 | // http://karma-runner.github.io/0.13/config/browsers.html 13 | // 2. add it to the `browsers` array below. 14 | browsers: ['PhantomJS'], 15 | frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'], 16 | reporters: ['spec', 'coverage'], 17 | files: ['./index.js'], 18 | preprocessors: { 19 | './index.js': ['webpack', 'sourcemap'] 20 | }, 21 | webpack: webpackConfig, 22 | webpackMiddleware: { 23 | noInfo: true 24 | }, 25 | coverageReporter: { 26 | dir: './coverage', 27 | reporters: [ 28 | { type: 'lcov', subdir: '.' }, 29 | { type: 'text-summary' } 30 | ] 31 | } 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /test/unit/specs/Dashboard.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Dashboard from '@/components/Dashboard' 3 | import router from '@/router' 4 | 5 | describe('Dashboard.vue', () => { 6 | it('should render correct contents', () => { 7 | const Constructor = Vue.extend(Dashboard) 8 | const vm = new Constructor({router}).$mount() 9 | expect(vm.$el.querySelector('.dashboard h1').textContent) 10 | .to.equal('Welcome to your truffle-vue dApp') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /truffle-box.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignore": [ 3 | "README.md", 4 | ".gitignore" 5 | ], 6 | "commands": { 7 | "Compile contracts": "truffle compile", 8 | "Migrate contracts": "truffle migrate", 9 | "Run dev server for front-end hot reloading": "npm run start", 10 | "Run unit and e2e tests": "npm run test/dapp", 11 | "Run truffle tests": "npm run test/truffle", 12 | "Run all tests": "npm run test", 13 | "Build for production": "npm run build" 14 | }, 15 | "hooks": { 16 | "post-unpack": "npm install" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: "localhost", 5 | port: 8545, 6 | gas: 500000, 7 | network_id: "*" // Match any network id 8 | } 9 | } 10 | }; 11 | --------------------------------------------------------------------------------