diff --git a/snapshot/snapshot_test.go b/snapshot/snapshot_test.go index ca0d419f..6b73c810 100644 --- a/snapshot/snapshot_test.go +++ b/snapshot/snapshot_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "os" "testing" "github.com/eoscanada/eos-go" @@ -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 @@ -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) @@ -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() +} diff --git a/system/setcode.go b/system/setcode.go index 82308934..e961f568 100644 --- a/system/setcode.go +++ b/system/setcode.go @@ -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"), @@ -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