Refactor and replace factory method random() with constructor.
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
#include "zcash/Address.hpp"
|
#include "zcash/Address.hpp"
|
||||||
#include "zcash/Note.hpp"
|
#include "zcash/Note.hpp"
|
||||||
|
|
||||||
|
#include "amount.h"
|
||||||
|
#include "random.h"
|
||||||
#include "librustzcash.h"
|
#include "librustzcash.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
@@ -53,10 +55,10 @@ TEST(SaplingNote, TestVectors)
|
|||||||
|
|
||||||
TEST(SaplingNote, Random)
|
TEST(SaplingNote, Random)
|
||||||
{
|
{
|
||||||
// Test creating random notes using the same sk
|
// Test creating random notes using the same spending key
|
||||||
auto sk = SaplingSpendingKey::random();
|
auto address = SaplingSpendingKey::random().default_address().get();
|
||||||
SaplingNote note1 = SaplingNote::random(sk);
|
SaplingNote note1(address, GetRand(MAX_MONEY));
|
||||||
SaplingNote note2 = SaplingNote::random(sk);
|
SaplingNote note2(address, GetRand(MAX_MONEY));
|
||||||
|
|
||||||
ASSERT_EQ(note1.d, note2.d);
|
ASSERT_EQ(note1.d, note2.d);
|
||||||
ASSERT_EQ(note1.pk_d, note2.pk_d);
|
ASSERT_EQ(note1.pk_d, note2.pk_d);
|
||||||
@@ -64,8 +66,7 @@ TEST(SaplingNote, Random)
|
|||||||
ASSERT_NE(note1.r, note2.r);
|
ASSERT_NE(note1.r, note2.r);
|
||||||
|
|
||||||
// Test diversifier and pk_d are not the same for different spending keys
|
// Test diversifier and pk_d are not the same for different spending keys
|
||||||
sk = SaplingSpendingKey::random();
|
SaplingNote note3(SaplingSpendingKey::random().default_address().get(), GetRand(MAX_MONEY));
|
||||||
SaplingNote note3 = SaplingNote::random(sk);
|
|
||||||
ASSERT_NE(note1.d, note3.d);
|
ASSERT_NE(note1.d, note3.d);
|
||||||
ASSERT_NE(note1.pk_d, note3.pk_d);
|
ASSERT_NE(note1.pk_d, note3.pk_d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,15 +40,11 @@ uint256 SproutNote::nullifier(const SproutSpendingKey& a_sk) const {
|
|||||||
return PRF_nf(a_sk, rho);
|
return PRF_nf(a_sk, rho);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a note based on a given spending key, with random r and value. Useful for testing.
|
// Construct and populate Sapling note for a given payment address and value.
|
||||||
SaplingNote SaplingNote::random(const SaplingSpendingKey& sk) {
|
SaplingNote::SaplingNote(const SaplingPaymentAddress& address, const uint64_t value) : BaseNote(value) {
|
||||||
auto addr = sk.default_address().get();
|
d = address.d;
|
||||||
auto d = addr.d;
|
pk_d = address.pk_d;
|
||||||
auto pk_d = addr.pk_d;
|
|
||||||
uint256 r;
|
|
||||||
librustzcash_sapling_generate_r(r.begin());
|
librustzcash_sapling_generate_r(r.begin());
|
||||||
auto value = GetRand(10000);
|
|
||||||
return SaplingNote(d, pk_d, value, r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call librustzcash to compute the commitment
|
// Call librustzcash to compute the commitment
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ public:
|
|||||||
|
|
||||||
SaplingNote() {};
|
SaplingNote() {};
|
||||||
|
|
||||||
|
SaplingNote(const SaplingPaymentAddress &address, uint64_t value);
|
||||||
|
|
||||||
virtual ~SaplingNote() {};
|
virtual ~SaplingNote() {};
|
||||||
|
|
||||||
virtual uint256 cm() const override;
|
virtual uint256 cm() const override;
|
||||||
|
|
||||||
uint256 nullifier(const SaplingSpendingKey &sk, const uint64_t position) const;
|
uint256 nullifier(const SaplingSpendingKey &sk, const uint64_t position) const;
|
||||||
|
|
||||||
static SaplingNote random(const SaplingSpendingKey &sk);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BaseNotePlaintext {
|
class BaseNotePlaintext {
|
||||||
|
|||||||
Reference in New Issue
Block a user