-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(commands): setup simple integration framework
* test(commands): setup simple integration framework * chore(ci): enable codecov * docs(readme): update badges * chore(ci): add caching to circleci * chore: fix linting errors * address first round of cr * chore(ci): add codecov config * fix broken import * fixup tests and lint after rebase
- Loading branch information
1 parent
1be8d3f
commit 6506f51
Showing
39 changed files
with
907 additions
and
226 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 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,6 @@ | ||
coverage: | ||
range: 70..100 | ||
round: down | ||
precision: 2 | ||
|
||
comment: false |
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,3 +1,4 @@ | ||
go-filecoin | ||
.task | ||
*.coverprofile | ||
*.coverprofile | ||
*.out |
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
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,38 +1,60 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/filecoin-project/go-filecoin/types" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/filecoin-project/go-filecoin/node" | ||
"github.com/filecoin-project/go-filecoin/testhelpers" | ||
"github.com/filecoin-project/go-filecoin/wallet" | ||
) | ||
|
||
func TestAddrsNew(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
nd := &node.Node{Wallet: wallet.New()} | ||
|
||
out, err := testhelpers.RunCommand(addrsNewCmd, nil, nil, &Env{node: nd}) | ||
assert.NoError(err) | ||
|
||
assert.NoError(out.HasLine(nd.Wallet.GetAddresses()[0].String())) | ||
// makeAddr must be run inside a `withDaemon` context to have access to | ||
// the default daemon. | ||
func makeAddr(t *testing.T) string { | ||
t.Helper() | ||
outNew := runSuccess(t, "go-filecoin wallet addrs new") | ||
addr := strings.Trim(outNew.ReadStdout(), "\n") | ||
assert.NotEmpty(t, addr) | ||
return addr | ||
} | ||
|
||
func TestAddrsList(t *testing.T) { | ||
func TestAddrsNewAndList(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
nd := &node.Node{Wallet: wallet.New()} | ||
a1 := nd.Wallet.NewAddress() | ||
a2 := nd.Wallet.NewAddress() | ||
a3 := nd.Wallet.NewAddress() | ||
daemon := withDaemon(func() { | ||
addrs := make([]string, 10) | ||
for i := 0; i < 10; i++ { | ||
addrs[i] = makeAddr(t) | ||
} | ||
|
||
outList := runSuccess(t, "go-filecoin wallet addrs list") | ||
list := outList.ReadStdout() | ||
|
||
for _, addr := range addrs { | ||
assert.Contains(list, addr) | ||
} | ||
}) | ||
assert.NoError(daemon.Error) | ||
assert.Equal(daemon.Code, 0) | ||
} | ||
|
||
out, err := testhelpers.RunCommand(addrsListCmd, nil, nil, &Env{node: nd}) | ||
assert.NoError(err) | ||
func TestWalletBalance(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
assert.NoError(out.HasLine(a1.String())) | ||
assert.NoError(out.HasLine(a2.String())) | ||
assert.NoError(out.HasLine(a3.String())) | ||
daemon := withDaemon(func() { | ||
addr := makeAddr(t) | ||
|
||
t.Log("[failure] not found") | ||
balance := run(fmt.Sprintf("go-filecoin wallet balance %s", addr)) | ||
assert.Contains(balance.ReadStderr(), "not found") | ||
assert.Equal(balance.Code, 1) | ||
assert.Empty(balance.ReadStdout()) | ||
|
||
t.Log("[success] balance 100000") | ||
balance = runSuccess(t, fmt.Sprintf("go-filecoin wallet balance %s", types.Address("filecoin"))) | ||
assert.Contains(balance.ReadStdout(), "100000") | ||
}) | ||
assert.NoError(daemon.Error) | ||
assert.Equal(daemon.Code, 0) | ||
} |
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 |
---|---|---|
@@ -1,25 +1,37 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/filecoin-project/go-filecoin/node" | ||
"github.com/filecoin-project/go-filecoin/testhelpers" | ||
) | ||
|
||
func TestId(t *testing.T) { | ||
assert := assert.New(t) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
nd, err := node.New(ctx) | ||
assert.NoError(err) | ||
defer nd.Stop() | ||
|
||
out, err := testhelpers.RunCommand(idCmd, nil, nil, &Env{node: nd}) | ||
assert.NoError(err) | ||
runWithDaemon("go-filecoin id", func(id *output) { | ||
assert.NoError(id.Error) | ||
assert.Equal(id.Code, 0) | ||
assert.Empty(id.ReadStderr()) | ||
|
||
idContent := id.ReadStdout() | ||
assert.Containsf(idContent, "/ip4/127.0.0.1/tcp/6000/ipfs/", "default addr") | ||
assert.Contains(idContent, "ID") | ||
}) | ||
} | ||
|
||
func TestIdFormat(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
runWithDaemon("go-filecoin id --format=\"<id>\\t<aver>\\t<pver>\\t<pubkey>\\n<addrs>\"", func(id *output) { | ||
assert.NoError(id.Error) | ||
assert.Equal(id.Code, 0) | ||
assert.Empty(id.ReadStderr()) | ||
|
||
assert.Contains(out.Raw, nd.Host.ID().Pretty()) | ||
idContent := id.ReadStdout() | ||
assert.Contains(idContent, "\t") | ||
assert.Contains(idContent, "\n") | ||
assert.Containsf(idContent, "/ip4/127.0.0.1/tcp/6000/ipfs/", "default addr") | ||
assert.NotContains(idContent, "ID") | ||
}) | ||
} |
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
Oops, something went wrong.