現在「SolidityとEthereumによる 実践スマートコントラクト開発」(オライリー・ジャパン)を読みながら、本誌のコードを書き写しています。
その中で、コードのテスト(Truffle Test)を行なうため、try catchが採用されており、実際にやってみると、以下のようなエラーが出てしまいます。
setBeneficiary
throws and error when called from a non-owner account:
AssertionError: should not be permitted: expected undefined to equal 'Ownable:caller is not the >owner'
at Context.<anonymous> (test/fundraiser_test.js:71:16)
エラーの該当するコードの抜粋は以下の2番めのit文となります。
◎質問
1)エラーの原因について、お気づきな点がありましたら、どうぞご指摘ください。
2)const actualError = err.reasonについて、少なくともネットで調べた限り、errにreasonというプロパティを見つけることが出来ませんでした。これは、どのようなプロパティなのでしょうか。
describe("setBeneficiary", () => { const newBeneficiary = accounts[2]; it("updated beneficiary when called by owner account", async () => { await fundraiser.setBeneficiary(newBeneficiary, {from: owner}); const actualBeneficiary = await fundraiser.beneficiary(); assert.equal(actualBeneficiary, newBeneficiary, "beneficiaries should match"); }); it("throws and error when called from a non-owner account", async () => { try { await fundraiser.setBeneficiary(newBeneficiary, {from: accounts[3]}); assert.fail("withdraw was not restricted to owners") } catch(err) { const expectedError = "Ownable:caller is not the owner"; const actualError = err.reason; assert.equal(actualError, expectedError, "should not be permitted") } }); });
すべてのコードは以下にてご覧になれます。
本件の(テスト)コードは、その中のtest/fundraiser_test.jsに、
テストの際に呼び出すコントラクトはcontracts/Fundraiser.sol
となります。
https://github.com/okahijiki/fundraiser
以上、よろしくお願いいたします。

あなたの回答
tips
プレビュー