Skip to content

Commit

Permalink
fix(cli): use StoreView in contract test
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Mar 8, 2023
1 parent 9c30b06 commit a004926
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
19 changes: 19 additions & 0 deletions packages/cli/contracts/src/tables/Table1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,30 @@ library Table1 {
return SchemaLib.encode(_schema);
}

/** Get the table's metadata */
function getMetadata() internal pure returns (string memory, string[] memory) {
string[] memory _fieldNames = new string[](7);
_fieldNames[0] = "v1";
_fieldNames[1] = "v2";
_fieldNames[2] = "v3";
_fieldNames[3] = "v4";
_fieldNames[4] = "v5";
_fieldNames[5] = "v6";
_fieldNames[6] = "v7";
return ("Table1", _fieldNames);
}

/** Register the table's schema */
function registerSchema() internal {
StoreSwitch.registerSchema(_tableId, getSchema());
}

/** Set the table's metadata */
function setMetadata() internal {
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames);
}

/** Get v1 */
function getV1(
uint256 k1,
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/contracts/test/tablegen.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
pragma solidity >=0.8.0;

import "forge-std/Test.sol";
import {StoreView} from "@latticexyz/store/src/StoreView.sol";
import {Table1, Table1Data} from "../src/tables/Table1.sol";
import {Enum1, Enum2} from "../src/types.sol";

contract tablegenTest is Test {
function isStore() external view {}

contract tablegenTest is Test, StoreView {
function testTable1SetAndGet() public {
Table1.registerSchema();

Expand Down

0 comments on commit a004926

Please sign in to comment.