Skip to content

Commit d57d078

Browse files
committed
test
1 parent 5b4117e commit d57d078

File tree

4 files changed

+100
-87
lines changed

4 files changed

+100
-87
lines changed

proto/confidentialtransfers/query.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ message DecryptedCtAccount {
5757
bytes public_key = 1; // serialized public key
5858
uint32 pending_balance_lo = 2; // lo bits of the pending balance
5959
uint64 pending_balance_hi = 3; // hi bits of the pending balance
60-
uint64 combined_pending_balance = 4; // combined pending balance
60+
string combined_pending_balance = 4; // combined pending balance
6161
uint32 pending_balance_credit_counter = 5;
6262
string available_balance = 6; // decrypted available balance
6363
string decryptable_available_balance = 7; // decrypted aes encrypted available balance

x/confidentialtransfers/keeper/msg_server_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ func (suite *KeeperTestSuite) TestMsgServer_DepositBasic() {
331331
// Check that the account has been updated
332332
updatedAccount, _ := suite.App.ConfidentialTransfersKeeper.GetAccount(suite.Ctx, testAddr.String(), DefaultTestDenom)
333333

334-
oldPendingBalancePlaintext = newPendingBalancePlaintext
334+
oldPendingBalancePlaintext = oldPendingBalancePlaintext.Set(newPendingBalancePlaintext)
335335
newPendingBalancePlaintext, _, _, _ = updatedAccount.GetPendingBalancePlaintext(teg, keyPair)
336336
suite.Require().Equal(
337-
new(big.Int).Add(oldPendingBalancePlaintext, big.NewInt(int64(depositStruct.Amount))).String(),
338-
newPendingBalancePlaintext.String(),
337+
new(big.Int).Add(oldPendingBalancePlaintext, big.NewInt(int64(depositStruct.Amount))),
338+
newPendingBalancePlaintext,
339339
"Pending balances should have increased by the deposit amount")
340340

341341
// Check that the amount in the bank module are changed correctly.
@@ -501,7 +501,7 @@ func (suite *KeeperTestSuite) TestMsgServer_WithdrawHappyPath() {
501501
oldBalanceDecrypted, _ := teg.DecryptLargeNumber(keyPair.PrivateKey, initialState.AvailableBalance, elgamal.MaxBits32)
502502
newBalanceDecrypted, _ := teg.DecryptLargeNumber(keyPair.PrivateKey, account.AvailableBalance, elgamal.MaxBits32)
503503
newTotal := new(big.Int).Sub(oldBalanceDecrypted, withdrawAmount)
504-
suite.Require().Equal(newTotal.String(), newBalanceDecrypted.String())
504+
suite.Require().Equal(newTotal, newBalanceDecrypted)
505505

506506
// Check that the DecryptableAvailableBalances were updated correctly
507507
suite.Require().Equal(req.DecryptableBalance, account.DecryptableAvailableBalance)
@@ -1029,14 +1029,14 @@ func (suite *KeeperTestSuite) TestMsgServer_TransferHappyPath() {
10291029
transferAmountBigInt := new(big.Int).SetUint64(transferAmount)
10301030
senderOldBalanceDecrypted, _ := teg.DecryptLargeNumber(senderKeypair.PrivateKey, initialSenderState.AvailableBalance, elgamal.MaxBits32)
10311031
senderNewBalanceDecrypted, _ := teg.DecryptLargeNumber(senderKeypair.PrivateKey, senderAccountState.AvailableBalance, elgamal.MaxBits32)
1032-
suite.Require().Equal(new(big.Int).Sub(senderOldBalanceDecrypted, transferAmountBigInt).String(), senderNewBalanceDecrypted.String(), "AvailableBalance of sender should be decreased")
1032+
suite.Require().Equal(new(big.Int).Sub(senderOldBalanceDecrypted, transferAmountBigInt), senderNewBalanceDecrypted, "AvailableBalance of sender should be decreased")
10331033

10341034
// Verify that the DecryptableAvailableBalances were updated as well and that they match the available balances.
10351035
senderAesKey, _ := encryption.GetAESKey(*senderPk, DefaultTestDenom)
10361036
senderOldDecryptableBalanceDecrypted, _ := encryption.DecryptAESGCM(initialSenderState.DecryptableAvailableBalance, senderAesKey)
10371037
senderNewDecryptableBalanceDecrypted, _ := encryption.DecryptAESGCM(senderAccountState.DecryptableAvailableBalance, senderAesKey)
1038-
suite.Require().Equal(new(big.Int).Sub(senderOldDecryptableBalanceDecrypted, transferAmountBigInt).String(), senderNewDecryptableBalanceDecrypted.String())
1039-
suite.Require().Equal(senderNewBalanceDecrypted.String(), senderNewDecryptableBalanceDecrypted.String())
1038+
suite.Require().Equal(new(big.Int).Sub(senderOldDecryptableBalanceDecrypted, transferAmountBigInt), senderNewDecryptableBalanceDecrypted)
1039+
suite.Require().Equal(senderNewBalanceDecrypted, senderNewDecryptableBalanceDecrypted)
10401040

10411041
// On the other hand, available balances of the recipient account should not have been altered
10421042
recipientAccountState, _ := suite.App.ConfidentialTransfersKeeper.GetAccount(suite.Ctx, recipientAddr.String(), DefaultTestDenom)

x/confidentialtransfers/types/account.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ func (a *Account) GetPendingBalancePlaintext(decryptor *elgamal.TwistedElGamal,
4646
return nil, nil, nil, err
4747
}
4848

49-
// Shift the 48-bit number by 32 bits to the left
50-
actualPendingBalanceHi.Lsh(actualPendingBalanceHi, 16) // Equivalent to hi << 32
51-
5249
// Combine by adding hiBig with loBig
5350
combined := utils.CombinePendingBalances(actualPendingBalanceLo, actualPendingBalanceHi)
5451
return combined, actualPendingBalanceLo, actualPendingBalanceHi, nil
@@ -80,9 +77,9 @@ func (a *Account) Decrypt(decryptor *elgamal.TwistedElGamal, keypair *elgamal.Ke
8077

8178
return &DecryptedCtAccount{
8279
PublicKey: a.PublicKey.ToAffineCompressed(),
83-
PendingBalanceLo: uint32(pendingBalanceLo),
84-
PendingBalanceHi: pendingBalanceHi,
85-
CombinedPendingBalance: pendingBalanceCombined,
80+
PendingBalanceLo: uint32(pendingBalanceLo.Uint64()),
81+
PendingBalanceHi: pendingBalanceHi.Uint64(),
82+
CombinedPendingBalance: pendingBalanceCombined.String(),
8683
PendingBalanceCreditCounter: uint32(a.PendingBalanceCreditCounter),
8784
AvailableBalance: availableBalanceString,
8885
DecryptableAvailableBalance: aesAvailableBalance.String(),

0 commit comments

Comments
 (0)