6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TruffleがVyperをサポートしたので触ってみる

Posted at

Truffleのv5Vyperがサポートされたので触ってみます。
環境構築は地味に面倒なのでDockerイメージを作成しました(Dockerfile)。

利用手順

docker run -it sot528/truffle-vyper-test

コンテナ内で挙動確認

vyper-example-boxをunboxしているので↓のコマンドでテストが走ります。

$ truffle test

Using network 'test'.



  Contract: VyperStorage
    ✓ ...should store the value 89. (114ms)


  1 passing (129ms)

VyperのContractのテストが走りました。
テスト対象のContract ./contracts/VyperStorage.vy をいじってtruffle compileすればいろいろ挙動確認できます。

stored_data: uint256

@public
def set(new_value : uint256):
    self.stored_data = new_value

@public
@constant
def get() -> uint256:
    return self.stored_data

テストファイルは ./test/vyperStorage.js です。

const VyperStorage = artifacts.require("VyperStorage");

contract("VyperStorage", () => {
  it("...should store the value 89.", async () => {
    const storage = await VyperStorage.deployed();

    // Set value of 89
    await storage.set(89);

    // Get stored value
    const storedData = await storage.get();

    assert.equal(storedData, 89, "The value 89 was not stored.");
  });
});

以下のようなエラーが出る場合は build以下を削除すると解決します。

Error parsing /code/contracts/VyperStorage.vy: ParsedContract.sol:1:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
stored_data: uint256
^---------^
Compilation failed. See above.
Truffle v5.0.0 (core: 5.0.0)

以上。
Vyperも着実に環境が整ってきていますね。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?