├── README.md ├── compile.js ├── contracts └── inbox.sol ├── package-lock.json ├── package.json └── test └── inbox.test.js /README.md: -------------------------------------------------------------------------------- 1 | You can add changes to contracts.sol 2 | The contract have some issues 3 | -------------------------------------------------------------------------------- /compile.js: -------------------------------------------------------------------------------- 1 | const path= require ('path'); 2 | const fs= require('fs'); 3 | const solc = require('solc'); 4 | const inboxPath= path.resolve(__dirname,'contracts','inbox.sol'); 5 | const source =fs.readFileSync(inboxPath , 'utf-8'); 6 | 7 | module.exports = solc.compile(source , 1).contracts [':Inbox']; -------------------------------------------------------------------------------- /contracts/inbox.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.4.17 ; 4 | 5 | contract Inbox { 6 | string public message; 7 | 8 | function Inbox(string initialMessage) public { 9 | message = initialMessage; 10 | } 11 | 12 | function setMessage(string newMessage) public { 13 | message = newMessage; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inbox", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "ganache-cli": "^6.12.2", 13 | "mocha": "^10.0.0", 14 | "solc": "^0.4.17", 15 | "web3": "^1.7.5" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/inbox.test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const ganache = require('ganache-cli'); 3 | const Web3 = require('web3'); 4 | const web3 = new Web3 (ganache.provider()); 5 | let accounts; 6 | let inbox; 7 | const {interface , bytecode}= require('../compile'); 8 | 9 | beforeEach(async ()=> 10 | { 11 | accounts = await web3.eth.getAccounts() 12 | inbox = await new web3.eth.Contract(JSON.parse(interface)) 13 | .deploy({data : bytecode, arguments : ['Hi there']}) 14 | .send({from : accounts[0], gas:'1000000'}) 15 | }); 16 | 17 | describe('inbox' , ()=> 18 | { 19 | it('deploys a contract', ()=> { 20 | 21 | assert.ok(inbox.options.address); 22 | }); 23 | 24 | it('has a default message', async ()=> 25 | { 26 | const message= await inbox.methods.message().call(); 27 | assert.equal(message, 'Hi there'); 28 | }); 29 | }); 30 | /*describe('Car',()=> 31 | { 32 | it('can park' , ()=> 33 | { 34 | const car=new Car(); 35 | assert.equal(car.park(),'stopped'); 36 | } ); 37 | } );*/ --------------------------------------------------------------------------------