Skip to content

Commit

Permalink
feat:check code gen in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Jul 20, 2022
1 parent d6fc239 commit de146af
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 80 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ jobs:
- name: Build
run: |
make build
make install
- name: Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
golangci-lint run --timeout 10m
golangci-lint run ./... --timeout 10m
- name: gen-check
run: |
export PATH=$PATH:/usr/local/tinygo/bin
make code-gen
git status --porcelain
test -z "$(git status --porcelain)"
- name: Test
run: |
Expand Down
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
current_dir = $(shell pwd)

build-tool:
build:
ifeq (,$(wildcard ${current_dir}/bin/go-fvm-sdk-tools))
cargo build -p go-fvm-sdk-tools --out-dir ${current_dir}/bin --release -Z unstable-options
cargo build -p go-fvm-sdk-tools --release
endif

build: build-tool

gen:
install:build
cp -f ./target/release/go-fvm-sdk-tools /usr/local/bin

code-gen:
cd ./sdk/gen && go run main.go
cd ./sdk/cases && ./gen.sh
cd ./examples/hellocontract/gen && go run main.go
cd ./examples/erc20/gen && go run main.go

clean:
rm -rf ./bin/*

gen-case:
cd ./sdk/cases && ./gen.sh ${current_dir}

test: build gen-case
cd ./sdk/cases && ${current_dir}/bin/go-fvm-sdk-tools test
test: build code-gen
cd ./sdk/cases && go-fvm-sdk-tools test
cd ./examples/hellocontract && go-fvm-sdk-tools test
cd ./examples/erc20 && go-fvm-sdk-tools test
11 changes: 1 addition & 10 deletions examples/hellocontract/contract/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ func NewState() *State {
func Constructor() error {
// This constant should be part of the SDK.
// var ActorID = 1;

caller, err := sdk.Caller()
if err != nil {
sdk.Abort(ferrors.USR_ILLEGAL_STATE, "unable to get caller")
}

if caller != 1 {
sdk.Abort(ferrors.USR_ILLEGAL_STATE, "constructor invoked by non-init actor")
}
_ = sdk.SaveState(&State{})
_ = sdk.Constructor(&State{})
return nil
}

Expand Down
13 changes: 10 additions & 3 deletions examples/hellocontract/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ module hellocontract
go 1.16

replace (
erc20 => ./
github.com/davecgh/go-spew => github.com/ipfs-force-community/go-spew v1.1.2-0.20220524052205-0034150c051a
github.com/filecoin-project/go-address => github.com/ipfs-force-community/go-address v0.0.7-0.20220524010936-42617a156be1
github.com/filecoin-project/go-state-types => github.com/ipfs-force-community/go-state-types v0.1.8-0.20220523102255-d400d329d9c1
github.com/ipfs-force-community/go-fvm-sdk => ../..
github.com/ipfs/go-block-format => github.com/ipfs-force-community/go-block-format v0.0.4-0.20220425095807-073e9266335c
github.com/klauspost/cpuid/v2 => github.com/ipfs-force-community/cpuid/v2 v2.0.13-0.20220421095210-bfbeb72f34dd
github.com/ipfs/go-ipld-cbor => github.com/ipfs-force-community/go-ipld-cbor v0.0.7-0.20220713070731-f5190aacb1a4
github.com/klauspost/cpuid/v2 => github.com/ipfs-force-community/cpuid/v2 v2.0.13-0.20220523085810-ac111993ce74
github.com/minio/blake2b-simd => github.com/ipfs-force-community/blake2b-simd v0.0.0-20220523083450-6e9a68832d69
github.com/minio/sha256-simd => github.com/ipfs-force-community/sha256-simd v1.0.1-0.20220421100150-fcbba4b6ea96
github.com/polydawn/refmt => github.com/hunjixin/refmt v0.0.0-20220520091210-cb3c7d292019
github.com/stretchr/testify => github.com/ipfs-force-community/testify v1.7.1-0.20220616060316-ea4f53121ac3
github.com/whyrusleeping/cbor-gen => github.com/ipfs-force-community/cbor-gen v0.0.0-20220421100448-dc345220256c
golang.org/x/crypto => github.com/ipfs-force-community/crypto v0.0.0-20220421095836-dd8044371872
hellocontract => ./
golang.org/x/crypto => github.com/ipfs-force-community/crypto v0.0.0-20220523090957-2aff239c26f7
lukechampine.com/blake3 => github.com/ipfs-force-community/blake3 v1.1.8-0.20220609024944-51450f2b2fc0
)

Expand Down
69 changes: 18 additions & 51 deletions examples/hellocontract/go.sum

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions examples/hellocontract/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"accounts": [
{
"priv_key": "6c3b9aa767f785b537c0d8ba5fa54677e6a6e281320dfbb27c889b8fa460670f",
"address": "f1m674sjwmga36qi3wkowt3wozwpahrkdlvd4tpci",
"balance": 10000
},
{
"priv_key": "b10da48cea4c09676b8e0efcd806941465060736032bb898420d0863dca72538",
"address": "f1dwyrbh74hr5nwqv2gjedjyvgphxxkffxug4rkkq",
"balance": 10000
},
{
"priv_key": "c51b8a31c98b9fe13065b485c9f8658c194c430843570ccac2720a3b30b47adb",
"address": "f15o3zaqettjmmarblwzjr66lwddsi6rbtxjwzngq",
"balance": 10000
}
],
"contracts":[
{
"name": "helloworld",
"binary": "hellocontract.wasm",
"constructor": "",
"cases": [

]
}
]
}
Binary file added sdk/cases/adt.wasm
Binary file not shown.
4 changes: 1 addition & 3 deletions sdk/cases/gen.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash

root_dir=$1
echo ${root_dir}
for i in *.go; do
filename=$(echo $i | cut -d . -f1)
target="${filename}.wasm"
${root_dir}/bin/go-fvm-sdk-tools build --output $target --wat -- $i
go-fvm-sdk-tools build --output $target --wat -- $i
echo "Build ${target} successfully"
done
Binary file added sdk/cases/rand.wasm
Binary file not shown.

0 comments on commit de146af

Please sign in to comment.