update NewCoin and crypto.Signature

This commit is contained in:
rhuairahrighairigh 2018-09-19 15:49:00 -04:00
parent b499c88f19
commit da335a91fe
5 changed files with 24 additions and 24 deletions

View File

@ -1,9 +1,10 @@
package paychan package paychan
import ( import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestEndBlocker(t *testing.T) { func TestEndBlocker(t *testing.T) {
@ -14,7 +15,7 @@ func TestEndBlocker(t *testing.T) {
ctx, _, channelKeeper, addrs, _, _, _ := createMockApp(accountSeeds) ctx, _, channelKeeper, addrs, _, _, _ := createMockApp(accountSeeds)
sender := addrs[0] sender := addrs[0]
receiver := addrs[1] receiver := addrs[1]
coins := sdk.Coins{sdk.NewCoin("KVA", 10)} coins := sdk.Coins{sdk.NewInt64Coin("KVA", 10)}
// create new channel // create new channel
channelID := ChannelID(0) // should be 0 as first channel channelID := ChannelID(0) // should be 0 as first channel
@ -26,11 +27,10 @@ func TestEndBlocker(t *testing.T) {
channelKeeper.setChannel(ctx, channel) channelKeeper.setChannel(ctx, channel)
// create closing update and submittedUpdate // create closing update and submittedUpdate
payout := Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}} payout := Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}
update := Update{ update := Update{
ChannelID: channelID, ChannelID: channelID,
Payout: payout, Payout: payout,
//Sigs: [1]crypto.Signature{},
} }
sUpdate := SubmittedUpdate{ sUpdate := SubmittedUpdate{
Update: update, Update: update,

View File

@ -30,7 +30,7 @@ func TestKeeper(t *testing.T) {
"HappyPath", "HappyPath",
addrs[senderAccountIndex], addrs[senderAccountIndex],
addrs[receiverAccountIndex], addrs[receiverAccountIndex],
sdk.Coins{sdk.NewCoin("KVA", 10)}, sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
true, true,
false, false,
}, },
@ -38,7 +38,7 @@ func TestKeeper(t *testing.T) {
"NilAddress", "NilAddress",
sdk.AccAddress{}, sdk.AccAddress{},
sdk.AccAddress{}, sdk.AccAddress{},
sdk.Coins{sdk.NewCoin("KVA", 10)}, sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
false, false,
true, true,
}, },
@ -54,7 +54,7 @@ func TestKeeper(t *testing.T) {
"NegativeCoins", "NegativeCoins",
addrs[senderAccountIndex], addrs[senderAccountIndex],
addrs[receiverAccountIndex], addrs[receiverAccountIndex],
sdk.Coins{sdk.NewCoin("KVA", -57)}, sdk.Coins{sdk.NewInt64Coin("KVA", -57)},
false, false,
true, true,
}, },
@ -126,7 +126,7 @@ func TestKeeper(t *testing.T) {
) )
ctx, coinKeeper, channelKeeper, addrs, pubKeys, privKeys, genAccFunding := createMockApp(accountSeeds) ctx, coinKeeper, channelKeeper, addrs, pubKeys, privKeys, genAccFunding := createMockApp(accountSeeds)
coins := sdk.Coins{sdk.NewCoin("KVA", 10)} coins := sdk.Coins{sdk.NewInt64Coin("KVA", 10)}
// create new channel // create new channel
channelID := ChannelID(0) // should be 0 as first channel channelID := ChannelID(0) // should be 0 as first channel
@ -138,7 +138,7 @@ func TestKeeper(t *testing.T) {
channelKeeper.setChannel(ctx, channel) channelKeeper.setChannel(ctx, channel)
// create closing update // create closing update
payout := Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}} payout := Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}
update := Update{ update := Update{
ChannelID: channelID, ChannelID: channelID,
Payout: payout, Payout: payout,
@ -200,14 +200,14 @@ func TestKeeper(t *testing.T) {
{ {
"HappyPath", "HappyPath",
true, true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, senderAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
"sameAsSubmited", "sameAsSubmited",
false, false,
}, },
{ {
"NoChannel", "NoChannel",
false, false,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, senderAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
"empty", "empty",
true, true,
}, },
@ -221,35 +221,35 @@ func TestKeeper(t *testing.T) {
{ {
"NegativeCoins", "NegativeCoins",
true, true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", -5)}, sdk.Coins{sdk.NewCoin("KVA", 15)}}, senderAccountIndex, senderAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", -5)}, sdk.Coins{sdk.NewInt64Coin("KVA", 15)}}, senderAccountIndex, senderAccountIndex},
"empty", "empty",
true, true,
}, },
{ {
"TooManyCoins", "TooManyCoins",
true, true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 100)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, senderAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 100)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
"empty", "empty",
true, true,
}, },
{ {
"WrongSignature", "WrongSignature",
true, true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, otherAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, otherAccountIndex},
"empty", "empty",
true, true,
}, },
{ {
"WrongPubKey", "WrongPubKey",
true, true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, otherAccountIndex, senderAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, otherAccountIndex, senderAccountIndex},
"empty", "empty",
true, true,
}, },
{ {
"ReceiverSigned", "ReceiverSigned",
true, true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, receiverAccountIndex, receiverAccountIndex}, testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, receiverAccountIndex, receiverAccountIndex},
"empty", "empty",
true, true,
}, },
@ -266,7 +266,7 @@ func TestKeeper(t *testing.T) {
channel := Channel{ channel := Channel{
ID: chanID, // should be 0 as first channel ID: chanID, // should be 0 as first channel
Participants: [2]sdk.AccAddress{addrs[senderAccountIndex], addrs[receiverAccountIndex]}, Participants: [2]sdk.AccAddress{addrs[senderAccountIndex], addrs[receiverAccountIndex]},
Coins: sdk.Coins{sdk.NewCoin("KVA", 10)}, Coins: sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
} }
channelKeeper.setChannel(ctx, channel) channelKeeper.setChannel(ctx, channel)
} }

View File

@ -27,7 +27,7 @@ func createMockApp(accountSeeds []string) (sdk.Context, bank.Keeper, Keeper, []s
mApp.CompleteSetup([]*sdk.KVStoreKey{keyChannel}) mApp.CompleteSetup([]*sdk.KVStoreKey{keyChannel})
// create some accounts // create some accounts
genAccFunding := sdk.Coins{sdk.NewCoin("KVA", 1000)} genAccFunding := sdk.Coins{sdk.NewInt64Coin("KVA", 1000)}
genAccs, addrs, pubKeys, privKeys := createTestGenAccounts(accountSeeds, genAccFunding) genAccs, addrs, pubKeys, privKeys := createTestGenAccounts(accountSeeds, genAccFunding)
// initialize the app with these accounts // initialize the app with these accounts

View File

@ -61,7 +61,7 @@ func (p Payout) Sum() sdk.Coins {
type UpdateSignature struct { type UpdateSignature struct {
PubKey crypto.PubKey PubKey crypto.PubKey
CryptoSignature crypto.Signature CryptoSignature []byte
} }
// An update that has been submitted to the blockchain, but not yet acted on. // An update that has been submitted to the blockchain, but not yet acted on.

View File

@ -28,18 +28,18 @@ func TestSubmittedUpdatesQueue(t *testing.T) {
func TestPayout(t *testing.T) { func TestPayout(t *testing.T) {
t.Run("IsNotNegative", func(t *testing.T) { t.Run("IsNotNegative", func(t *testing.T) {
p := Payout{sdk.Coins{sdk.NewCoin("USD", 4), sdk.NewCoin("GBP", 0)}, sdk.Coins{sdk.NewCoin("USD", 129879234), sdk.NewCoin("GBP", 1)}} p := Payout{sdk.Coins{sdk.NewInt64Coin("USD", 4), sdk.NewInt64Coin("GBP", 0)}, sdk.Coins{sdk.NewInt64Coin("USD", 129879234), sdk.NewInt64Coin("GBP", 1)}}
assert.True(t, p.IsNotNegative()) assert.True(t, p.IsNotNegative())
p = Payout{sdk.Coins{sdk.NewCoin("USD", -4), sdk.NewCoin("GBP", 0)}, sdk.Coins{sdk.NewCoin("USD", 129879234), sdk.NewCoin("GBP", 1)}} p = Payout{sdk.Coins{sdk.NewInt64Coin("USD", -4), sdk.NewInt64Coin("GBP", 0)}, sdk.Coins{sdk.NewInt64Coin("USD", 129879234), sdk.NewInt64Coin("GBP", 1)}}
assert.False(t, p.IsNotNegative()) assert.False(t, p.IsNotNegative())
}) })
t.Run("Sum", func(t *testing.T) { t.Run("Sum", func(t *testing.T) {
p := Payout{ p := Payout{
sdk.Coins{sdk.NewCoin("EUR", 1), sdk.NewCoin("USD", -5)}, sdk.Coins{sdk.NewInt64Coin("EUR", 1), sdk.NewInt64Coin("USD", -5)},
sdk.Coins{sdk.NewCoin("EUR", 1), sdk.NewCoin("USD", 100), sdk.NewCoin("GBP", 1)}, sdk.Coins{sdk.NewInt64Coin("EUR", 1), sdk.NewInt64Coin("USD", 100), sdk.NewInt64Coin("GBP", 1)},
} }
expected := sdk.Coins{sdk.NewCoin("EUR", 2), sdk.NewCoin("GBP", 1), sdk.NewCoin("USD", 95)} expected := sdk.Coins{sdk.NewInt64Coin("EUR", 2), sdk.NewInt64Coin("GBP", 1), sdk.NewInt64Coin("USD", 95)}
assert.Equal(t, expected, p.Sum()) assert.Equal(t, expected, p.Sum())
}) })
} }