-
Notifications
You must be signed in to change notification settings - Fork 59
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
1 parent
1f681a9
commit 1fe5e88
Showing
8 changed files
with
80 additions
and
7 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package funds_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ipfs/go-datastore" | ||
dss "github.com/ipfs/go-datastore/sync" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/filecoin-project/specs-actors/actors/abi" | ||
"github.com/filecoin-project/specs-actors/actors/abi/big" | ||
|
||
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/funds" | ||
) | ||
|
||
func TestDealFunds(t *testing.T) { | ||
ds := dss.MutexWrap(datastore.NewMapDatastore()) | ||
key := datastore.NewKey("deal_funds_test") | ||
|
||
f, err := funds.NewDealFunds(ds, key) | ||
assert.NoError(t, err) | ||
|
||
// initializes to zero | ||
assert.Equal(t, f.Get(), big.Zero()) | ||
|
||
// reserve funds and return new total | ||
newAmount, err := f.Reserve(abi.NewTokenAmount(123)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, abi.NewTokenAmount(123), newAmount) | ||
assert.Equal(t, abi.NewTokenAmount(123), f.Get()) | ||
|
||
// reserve more funds and return new total | ||
newAmount, err = f.Reserve(abi.NewTokenAmount(100)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, abi.NewTokenAmount(223), newAmount) | ||
assert.Equal(t, abi.NewTokenAmount(223), f.Get()) | ||
|
||
// release funds and return new total | ||
newAmount, err = f.Release(abi.NewTokenAmount(123)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, abi.NewTokenAmount(100), newAmount) | ||
assert.Equal(t, abi.NewTokenAmount(100), f.Get()) | ||
|
||
// creating new funds will read stored value | ||
f, err = funds.NewDealFunds(ds, key) | ||
assert.NoError(t, err) | ||
assert.Equal(t, abi.NewTokenAmount(100), newAmount) | ||
assert.Equal(t, abi.NewTokenAmount(100), f.Get()) | ||
} |
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