Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

86_罗霄_第六次作业 #480

Open
wants to merge 3 commits into
base: 86-罗霄
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions Assignment #4
Original file line number Diff line number Diff line change
@@ -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");

});
});
});

Binary file added Assignment #6.zip
Binary file not shown.
16 changes: 10 additions & 6 deletions Lesson5/orgin/src/components/Employee.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down