DEV Community

sot528
sot528

Posted on

Try Vyper in Truffle v5.

Truffle v5 supported Vyper.
I made Docker image to try it easialy.(Dockerfile)

How to use

docker run -it sot528/truffle-vyper-test

In the container

It unboxed vyper-example-box. So you can use below.

$ truffle test

Using network 'test'.



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


  1 passing (129ms)

It works.
You can try anything via editing ./contracts/VyperStorage.vy and 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

The test file is ./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.");
  });
});

If you see the error below, then you should remove all of the files in 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)

Top comments (0)