-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package offchain_test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/suave/offchain" | ||
iface "github.com/ipfs/kubo/core/coreiface" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var api iface.CoreAPI | ||
|
||
func TestMain(m *testing.M) { | ||
// Check if IPFS is available in the environment before attempting | ||
// to run the integration tests. | ||
cmd := exec.Command("which", "ipfs") | ||
switch err := cmd.Run().(type) { | ||
case *exec.ExitError: | ||
if status := err.ExitCode(); status > 0 { | ||
log.Println("ipfs not found in $PATH. Skipping...") | ||
} else { | ||
os.Exit(status) // abort; we still don't know if IPFS is available | ||
} | ||
|
||
case error: | ||
log.Fatal(err) | ||
} | ||
|
||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestBlockstore(t *testing.T) { | ||
t.Parallel() | ||
|
||
env := offchain.Env{ | ||
IPFS: api, | ||
} | ||
require.NoError(t, env.Start(), "failed to bind offchain environment") | ||
defer func() { | ||
require.NoError(t, env.Stop(), "failed to release offchain environment") | ||
}() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,26 @@ | ||
package offchain | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/ethereum/go-ethereum/suave/datastore" | ||
"github.com/ipfs/go-cid" | ||
"github.com/ipfs/kubo/client/rpc" | ||
iface "github.com/ipfs/kubo/core/coreiface" | ||
) | ||
|
||
type Datastore interface { | ||
Get(context.Context, cid.Cid) (io.Reader, error) | ||
Put(context.Context, io.Reader) (cid.Cid, error) | ||
} | ||
|
||
type Env struct { | ||
Core iface.CoreAPI | ||
Store Datastore | ||
IPFS iface.CoreAPI | ||
} | ||
|
||
func (env *Env) Start() (err error) { | ||
if env.Store == nil { | ||
// Import IPFS into the off-chain environment | ||
if env.Core, err = rpc.NewLocalApi(); err == nil { | ||
env.Store = &datastore.IPFS{ | ||
API: env.Core, | ||
} | ||
} | ||
|
||
} | ||
|
||
// Bind IPFS into the off-chain environment | ||
env.IPFS, err = rpc.NewLocalApi() | ||
return | ||
} | ||
|
||
func (env *Env) Stop() error { | ||
return nil | ||
} | ||
|
||
func (env *Env) Blockstore() Blockstore { | ||
return Blockstore{ | ||
API: env.IPFS.Block(), | ||
} | ||
} |