mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
update NewCoin and crypto.Signature
This commit is contained in:
parent
b499c88f19
commit
da335a91fe
@ -1,9 +1,10 @@
|
||||
package paychan
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEndBlocker(t *testing.T) {
|
||||
@ -14,7 +15,7 @@ func TestEndBlocker(t *testing.T) {
|
||||
ctx, _, channelKeeper, addrs, _, _, _ := createMockApp(accountSeeds)
|
||||
sender := addrs[0]
|
||||
receiver := addrs[1]
|
||||
coins := sdk.Coins{sdk.NewCoin("KVA", 10)}
|
||||
coins := sdk.Coins{sdk.NewInt64Coin("KVA", 10)}
|
||||
|
||||
// create new channel
|
||||
channelID := ChannelID(0) // should be 0 as first channel
|
||||
@ -26,11 +27,10 @@ func TestEndBlocker(t *testing.T) {
|
||||
channelKeeper.setChannel(ctx, channel)
|
||||
|
||||
// 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{
|
||||
ChannelID: channelID,
|
||||
Payout: payout,
|
||||
//Sigs: [1]crypto.Signature{},
|
||||
}
|
||||
sUpdate := SubmittedUpdate{
|
||||
Update: update,
|
||||
|
@ -30,7 +30,7 @@ func TestKeeper(t *testing.T) {
|
||||
"HappyPath",
|
||||
addrs[senderAccountIndex],
|
||||
addrs[receiverAccountIndex],
|
||||
sdk.Coins{sdk.NewCoin("KVA", 10)},
|
||||
sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
|
||||
true,
|
||||
false,
|
||||
},
|
||||
@ -38,7 +38,7 @@ func TestKeeper(t *testing.T) {
|
||||
"NilAddress",
|
||||
sdk.AccAddress{},
|
||||
sdk.AccAddress{},
|
||||
sdk.Coins{sdk.NewCoin("KVA", 10)},
|
||||
sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
|
||||
false,
|
||||
true,
|
||||
},
|
||||
@ -54,7 +54,7 @@ func TestKeeper(t *testing.T) {
|
||||
"NegativeCoins",
|
||||
addrs[senderAccountIndex],
|
||||
addrs[receiverAccountIndex],
|
||||
sdk.Coins{sdk.NewCoin("KVA", -57)},
|
||||
sdk.Coins{sdk.NewInt64Coin("KVA", -57)},
|
||||
false,
|
||||
true,
|
||||
},
|
||||
@ -126,7 +126,7 @@ func TestKeeper(t *testing.T) {
|
||||
)
|
||||
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
|
||||
channelID := ChannelID(0) // should be 0 as first channel
|
||||
@ -138,7 +138,7 @@ func TestKeeper(t *testing.T) {
|
||||
channelKeeper.setChannel(ctx, channel)
|
||||
|
||||
// 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{
|
||||
ChannelID: channelID,
|
||||
Payout: payout,
|
||||
@ -200,14 +200,14 @@ func TestKeeper(t *testing.T) {
|
||||
{
|
||||
"HappyPath",
|
||||
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",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"NoChannel",
|
||||
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",
|
||||
true,
|
||||
},
|
||||
@ -221,35 +221,35 @@ func TestKeeper(t *testing.T) {
|
||||
{
|
||||
"NegativeCoins",
|
||||
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",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"TooManyCoins",
|
||||
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",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"WrongSignature",
|
||||
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",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"WrongPubKey",
|
||||
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",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"ReceiverSigned",
|
||||
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",
|
||||
true,
|
||||
},
|
||||
@ -266,7 +266,7 @@ func TestKeeper(t *testing.T) {
|
||||
channel := Channel{
|
||||
ID: chanID, // should be 0 as first channel
|
||||
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)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func createMockApp(accountSeeds []string) (sdk.Context, bank.Keeper, Keeper, []s
|
||||
mApp.CompleteSetup([]*sdk.KVStoreKey{keyChannel})
|
||||
|
||||
// create some accounts
|
||||
genAccFunding := sdk.Coins{sdk.NewCoin("KVA", 1000)}
|
||||
genAccFunding := sdk.Coins{sdk.NewInt64Coin("KVA", 1000)}
|
||||
genAccs, addrs, pubKeys, privKeys := createTestGenAccounts(accountSeeds, genAccFunding)
|
||||
|
||||
// initialize the app with these accounts
|
||||
|
@ -61,7 +61,7 @@ func (p Payout) Sum() sdk.Coins {
|
||||
|
||||
type UpdateSignature struct {
|
||||
PubKey crypto.PubKey
|
||||
CryptoSignature crypto.Signature
|
||||
CryptoSignature []byte
|
||||
}
|
||||
|
||||
// An update that has been submitted to the blockchain, but not yet acted on.
|
||||
|
@ -28,18 +28,18 @@ func TestSubmittedUpdatesQueue(t *testing.T) {
|
||||
|
||||
func TestPayout(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())
|
||||
|
||||
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())
|
||||
})
|
||||
t.Run("Sum", func(t *testing.T) {
|
||||
p := Payout{
|
||||
sdk.Coins{sdk.NewCoin("EUR", 1), sdk.NewCoin("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", -5)},
|
||||
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())
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user