「Source “truffle/DeployedAddresses.sol” not found: File import callback not supported」について

truffleのtestを実装中に以下のエラーが発生しました。

Source “truffle/Assert.sol” not found: File import callback not supported

または

Source “truffle/DeployedAddresses.sol” not found: File import callback not supported

ソースコードは以下です。

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/HelloWorld.sol";

contract TestHelloWorld {
  function testHelloWorld() public {
    HelloWorld hw = HelloWorld(DeployedAddresses.HelloWorld());
    Assert.equal(hw.getMessage(), "Hello World", "done");
  }
}

VSCodeで見ると以下のようになります。

目次

[非表示]

  1. 結論
  2. テスト結果

結論

このエラーが発生してもスルーで問題ないです。
truffle test実行時にtruffle/Assert.soltruffle/DeployedAddresses.solが生成されるようです。

開発エディタ上でエラーが発生していて少し気持ち悪いですが…。

テスト結果

テストを実行するすると以下のようになります。

% truffle test
]Using network 'development'.


Compiling your contracts...
===========================
> Compiling ./contracts/HelloWorld.sol
> Compiling ./contracts/WithdrawalContract.sol
> Compiling ./test/TestHelloWorld.sol
> Artifacts written to /var/folders/tn/t7n97ck12qx2nh05nk7b4bw80000gn/T/test--56483-DFpjtuo2yT2F
> Compiled successfully using:
   - solc: 0.8.17+commit.8df45f5f.Emscripten.clang


  TestHelloWorld
    ✔ testHelloWorld (203ms)


  1 passing (6s)