Solidity

嘗試全面測試合約

  • March 14, 2019
truffle(develop)> version
Truffle v5.0.5 (core: 5.0.5)
Solidity v0.5.0 (solc-js)
Node v10.15.1
const ApprovalContracts = artifacts.require('../../contracts/ApprovalContracts.sol'); 

contract ('ApprovalContracts', function (accounts) {
   it('initiates contract', async function() { 
       const contract = await ApprovalContracts.depolyed();
       const approver = await contract.approver.call(); 
       assert.equal(approver, 0xc7780C9521C2C2abED69f0D65BEbF9794C55ae94, "approvers don't match");
   });

   it('takes a deposit', async function() {
       const contract = await ApprovalContracts.depolyed();
       await contract.deposit(accounts[0], {value: 1e+18, from: accounts [1]});
       assert.equal(web3.eth.getBalance(contract.address), 1e+18, "amount did not match")
   })
})

錯誤

TypeError: ApprovalContracts.depolyed is not a function
 at Context.<anonymous> (test\approvalcontract.js:10:43)
 at web3.eth.getBlockNumber.then.result (C:\Users\_000\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\lib\testing\testrunner.js:134:1)
 at process._tickCallback (internal/process/next_tick.js:68:7)

TypeError: ApprovalContracts.depolyed is not a function
 at Context.<anonymous> (test\approvalcontract.js:17:43)
 at web3.eth.getBlockNumber.then.result (C:\Users\_000\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\lib\testing\testrunner.js:134:1)
 at process._tickCallback (internal/process/next_tick.js:68:7)

我非常確定它是 .depolyed 並且它期待一個功能。

});最後不見了。

const ApprovalContracts = artifacts.require('../../contracts/ApprovalContracts.sol'); 

contract('ApprovalContracts', function (accounts) { 

 it('initiates contract', async function() {  
   const contract = await ApprovalContracts.deployed();
   const approver = await contract.approver.call();     
   assert.equal(approver, 0xc7780C9521C2C2abED69f0D65BEbF9794C55ae94, "approvers don't match");    
 }); // <----I can see the error, not sure how to correct it.
});  // <--- To close the contract({}) block

希望能幫助到你。

引用自:https://ethereum.stackexchange.com/questions/68001