diff --git a/Assignment #4 b/Assignment #4 index d895f9d03..76adecc98 100644 --- a/Assignment #4 +++ b/Assignment #4 @@ -1,26 +1,41 @@ -pragma solidity ^0.4.14; - -import "truffle/Assert.sol"; -import "truffle/DeployedAddresses.sol"; -import "../contracts/payroll.sol"; - -contract TestPayroll { - - function testTotalSalary() public { - payroll payrolltest = payroll(DeployedAddresses.payroll()); - - address employeeId = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c; - - payrolltest.addEmployee(employeeId,1); - - Assert.equal(employees[employeeId].id, employeeId, "The employee has been added."); - uint expectedSalary1 = 1 ether; - Assert.equal(totalSalary, expectedSalary1, "It should store the value 1."); - - payrolltest.removeEmployee(employeeId); - - Assert.equal(employees[employeeId].id, "0x0", "The employee has been removed."); - uint expectedSalary2 = 0 ether; - Assert.equal(totalSalary, expectedSalary2, "It should store the value 0."); - } +var Payroll = artifacts.require("./Payroll.sol"); + +contract('Payroll', function(accounts) { + + it("...should add/remove employee.", function() { + return Payroll.deployed().then(function(instance) { + payrollInstance = instance; + + return payrollInstance.addEmployee(accounts[1], 1,{from: accounts[0]}); + }).then(function() { + return payrollInstance.removeEmployee(accounts[1]); + }).then(function() { + assert(true, "pass"); + }) + }); + + it("...should add valid address.", function() { + return Payroll.deployed().then(function(instance) { + payrollInstance = instance; + + return payrollInstance.addEmployee("0x0", 1,{from: accounts[0]}); + }).catch(function(error) { + assert(error.toString().includes('invalid opcode'), "expect exception here"); + + }); + }); + + it("...should add employee only once.", function() { + return Payroll.deployed().then(function(instance) { + payrollInstance = instance; + + return payrollInstance.addEmployee(accounts[1], 1,{from: accounts[0]}); + }).then(function() { + return payrollInstance.addEmployee(accounts[1], 1,{from: accounts[0]}); + }).catch(function(error) { + assert(error.toString().includes('invalid opcode'), "expect exception here"); + + }); + }); +}); diff --git a/Assignment #6.zip b/Assignment #6.zip new file mode 100644 index 000000000..adddedab7 Binary files /dev/null and b/Assignment #6.zip differ diff --git a/Lesson5/orgin/src/components/Employee.js b/Lesson5/orgin/src/components/Employee.js index 56daca687..73f9b7e6d 100644 --- a/Lesson5/orgin/src/components/Employee.js +++ b/Lesson5/orgin/src/components/Employee.js @@ -14,17 +14,21 @@ class Employer extends Component { } checkEmployee = () => { - const{payroll,employee,web3} = this.props; - payroll.employees.call(employee,{ - from:employee, - gas:1000000 + const{payroll,account,web3} = this.props; + payroll.employees.call(account,{ + from:account, }).then((result)=>{ - console.log(result) this.setState({ salary:web3.fromWei(result[1].toNumber()), - lastPaidDate: new Date(result[2].toNumber()*1000) + lastPaidDate: new Date(result[2].toNumber()*1000).toString() }); }); + + web3.eth.getBalance(account,(err,result) =>{ + this.setState({ + balance:web3.fromWei(result.toNumber()) + }); + }); } getPaid = () => {