-
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.
We persist deals to the disk to allow the continuation of deals after nodes are restarted. Additionally, we add: - A default address option to init - The ability to start, stop, and restart a test daemon Co-authored-by: rkowalick <[email protected]>
- Loading branch information
1 parent
1d7cd11
commit 45c8593
Showing
17 changed files
with
628 additions
and
190 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
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,35 +1,80 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-filecoin/fixtures" | ||
th "github.com/filecoin-project/go-filecoin/testhelpers" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestListAsks(t *testing.T) { | ||
t.Parallel() | ||
assert := assert.New(t) | ||
|
||
peer := th.NewDaemon(t, th.WithMiner(fixtures.TestMiners[0]), th.KeyFile(fixtures.KeyFilePaths()[2])).Start() | ||
defer peer.ShutdownSuccess() | ||
d := th.NewDaemon(t, th.KeyFile(fixtures.KeyFilePaths()[2])).Start() | ||
defer d.ShutdownSuccess() | ||
peer.ConnectSuccess(d) | ||
minerDaemon := th.NewDaemon(t, | ||
th.WithMiner(fixtures.TestMiners[0]), | ||
th.KeyFile(fixtures.KeyFilePaths()[0]), | ||
th.DefaultAddress(fixtures.TestAddresses[0]), | ||
).Start() | ||
defer minerDaemon.ShutdownSuccess() | ||
|
||
minerDaemon.CreateAsk(minerDaemon, fixtures.TestMiners[0], fixtures.TestAddresses[0], "20", "10") | ||
|
||
listAsksOutput := minerDaemon.RunSuccess("client", "list-asks").ReadStdoutTrimNewlines() | ||
assert.Equal(fixtures.TestMiners[0]+" 000 20 11", listAsksOutput) | ||
} | ||
|
||
func TestStorageDealsAfterRestart(t *testing.T) { | ||
t.Parallel() | ||
|
||
minerDaemon := th.NewDaemon(t, | ||
th.WithMiner(fixtures.TestMiners[0]), | ||
th.KeyFile(fixtures.KeyFilePaths()[0]), | ||
th.DefaultAddress(fixtures.TestAddresses[0]), | ||
).Start() | ||
defer minerDaemon.ShutdownSuccess() | ||
|
||
clientDaemon := th.NewDaemon(t, | ||
th.KeyFile(fixtures.KeyFilePaths()[1]), | ||
th.DefaultAddress(fixtures.TestAddresses[1]), | ||
).Start() | ||
defer clientDaemon.ShutdownSuccess() | ||
|
||
minerDaemon.UpdatePeerID() | ||
minerDaemon.RunSuccess("mining", "start") | ||
|
||
minerDaemon.ConnectSuccess(clientDaemon) | ||
|
||
minerDaemon.CreateAsk(minerDaemon, fixtures.TestMiners[0], fixtures.TestAddresses[0], "20", "10") | ||
dataCid := clientDaemon.RunWithStdin(strings.NewReader("HODLHODLHODL"), "client", "import").ReadStdoutTrimNewlines() | ||
|
||
proposeDealOutput := clientDaemon.RunSuccess("client", "propose-storage-deal", fixtures.TestMiners[0], dataCid, "0", "5").ReadStdoutTrimNewlines() | ||
|
||
splitOnSpace := strings.Split(proposeDealOutput, " ") | ||
|
||
dealCid := splitOnSpace[len(splitOnSpace)-1] | ||
|
||
minerDaemon.Restart() | ||
minerDaemon.RunSuccess("mining", "start") | ||
|
||
// create a miner with one ask | ||
minerAddr := d.CreateMinerAddr(peer, fixtures.TestAddresses[2]) | ||
d.CreateAsk(peer, minerAddr.String(), fixtures.TestAddresses[2], "20", "10") | ||
clientDaemon.Restart() | ||
|
||
// check ls | ||
expectedBaseHeight := 2 | ||
expectedExpiry := expectedBaseHeight + 10 | ||
ls := d.RunSuccess("client", "list-asks") | ||
expectedResult := fmt.Sprintf("%s 000 20 %d", minerAddr.String(), expectedExpiry) | ||
assert.Equal(expectedResult, strings.Trim(ls.ReadStdout(), "\n")) | ||
minerDaemon.ConnectSuccess(clientDaemon) | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
for { | ||
queryDealOutput := clientDaemon.RunSuccess("client", "query-storage-deal", dealCid).ReadStdout() | ||
if strings.Contains(queryDealOutput, "posted") { | ||
wg.Done() | ||
break | ||
} | ||
} | ||
}() | ||
th.WaitTimeout(&wg, 120*time.Second) | ||
} |
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
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
Oops, something went wrong.