Skip to content

Commit

Permalink
- transfer invalid inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Dec 10, 2024
1 parent 59e6e51 commit 6ff4137
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions x/confidentialtransfers/types/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,76 @@ import (
"testing"
)

func TestNewTransferErrorIfSenderEqualsRecipient(t *testing.T) {
senderPk, _ := encryption.GenerateKey()

_, err := NewTransfer(
senderPk,
"sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w",
"sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w",
"testDenom",
"",
nil,
0,
nil,
nil,
)
assert.EqualError(t, err, "sender and recipient addresses cannot be the same")
}

func TestNewTransferErrorIfInvalidDenom(t *testing.T) {
senderPk, _ := encryption.GenerateKey()
_, err := NewTransfer(
senderPk,
"sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w",
"sei12nqhfjuurt90p6yqkk2txnptrmuta40dl8mk3d",
"",
"",
nil,
0,
nil,
nil,
)
assert.EqualError(t, err, "denom is empty")
}

func TestNewTransferErrorIfInvalidCiphertext(t *testing.T) {
senderPk, _ := encryption.GenerateKey()
_, err := NewTransfer(
senderPk,
"sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w",
"sei12nqhfjuurt90p6yqkk2txnptrmuta40dl8mk3d",
"test",
"invalid",
nil,
0,
nil,
nil,
)
assert.EqualError(t, err, "illegal base64 data at input byte 4")
}

func TestNewTransferFailsIfInsufficientBalance(t *testing.T) {
testDenom := "factory/sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w/TEST"
senderPk, _ := encryption.GenerateKey()
aesKey, _ := encryption.GetAESKey(*senderPk, testDenom)
decryptableBalance, err := encryption.EncryptAESGCM(big.NewInt(10), aesKey)
transferAmount := uint64(100)

_, err = NewTransfer(
senderPk,
"sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w",
"sei12nqhfjuurt90p6yqkk2txnptrmuta40dl8mk3d",
testDenom,
decryptableBalance,
nil,
transferAmount,
nil,
nil,
)
assert.EqualError(t, err, "insufficient balance")
}

func TestNewTransfer(t *testing.T) {
testDenom := "factory/sei1ft98au55a24vnu9tvd92cz09pzcfqkm5vlx99w/TEST"
senderPk, _ := encryption.GenerateKey()
Expand Down

0 comments on commit 6ff4137

Please sign in to comment.