Skip to content

Commit

Permalink
fix snapshot test and added setcode content
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeless committed Jun 17, 2020
1 parent 48d4609 commit a51457d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
25 changes: 22 additions & 3 deletions snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"testing"

"github.com/eoscanada/eos-go"
Expand All @@ -13,6 +14,13 @@ import (
)

func TestSnapshotRead(t *testing.T) {
// "/tmp/0125111385-07750c59b24ed52d2dbf2048b67b58e9c9bd53ff5cc4550277718c1d5d800f73-snapshot.bin"
readSnapshotFile := os.Getenv("READ_SNAPSHOT_FILE")
if readSnapshotFile == "" || !fileExists(readSnapshotFile) {
t.Skipf("Environment varaible 'READ_SNAPSHOT_FILE' not set or value %q is not an exisiting file", readSnapshotFile)
return
}

tests := []struct {
name string
input string
Expand All @@ -27,9 +35,7 @@ func TestSnapshotRead(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
filename := "/tmp/0125111385-07750c59b24ed52d2dbf2048b67b58e9c9bd53ff5cc4550277718c1d5d800f73-snapshot.bin"
r, err := NewReader(filename)
fmt.Println("Filename", filename)
r, err := NewReader(readSnapshotFile)
defer r.Close()

assert.NoError(t, err)
Expand Down Expand Up @@ -94,3 +100,16 @@ func TestSnapshotRead(t *testing.T) {
})
}
}

func fileExists(path string) bool {
info, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}

if err != nil {
return false
}

return !info.IsDir()
}
32 changes: 25 additions & 7 deletions system/setcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,30 @@ func NewSetCode(account eos.AccountName, wasmPath string) (out *eos.Action, err
if err != nil {
return nil, err
}
return NewSetCodeContent(account, codeContent), nil
}

func NewSetABI(account eos.AccountName, abiPath string) (out *eos.Action, err error) {
abiContent, err := ioutil.ReadFile(abiPath)
if err != nil {
return nil, err
}

return NewSetAbiContent(account, abiContent)
}

func NewSetContractContent(account eos.AccountName, wasmContent, abiContent []byte) (out []*eos.Action, err error) {
codeAction := NewSetCodeContent(account, wasmContent)

abiAction, err := NewSetAbiContent(account, abiContent)
if err != nil {
return nil, err
}

return []*eos.Action{codeAction, abiAction}, nil
}

func NewSetCodeContent(account eos.AccountName, codeContent []byte) *eos.Action {
return &eos.Action{
Account: AN("eosio"),
Name: ActN("setcode"),
Expand All @@ -43,15 +66,10 @@ func NewSetCode(account eos.AccountName, wasmPath string) (out *eos.Action, err
VMVersion: 0,
Code: eos.HexBytes(codeContent),
}),
}, nil
}

func NewSetABI(account eos.AccountName, abiPath string) (out *eos.Action, err error) {
abiContent, err := ioutil.ReadFile(abiPath)
if err != nil {
return nil, err
}
}

func NewSetAbiContent(account eos.AccountName, abiContent []byte) (out *eos.Action, err error) {
var abiPacked []byte
if len(abiContent) > 0 {
var abiDef eos.ABI
Expand Down

0 comments on commit a51457d

Please sign in to comment.