Skip to content

Commit 5ce74bd

Browse files
Add products generating to test fixtures (#8)
* Add generator for product * fixed closure build * Generate products for simple products * Add generation of signatures for products * Add generated data to ft_receiver tests * Generate products in lib * Fix tests * Update contract/src/common.rs Co-authored-by: Vladas Zakrevskis <[email protected]> * Remove redundant refs --------- Co-authored-by: Vladas Zakrevskis <[email protected]>
1 parent 894cd05 commit 5ce74bd

File tree

10 files changed

+480
-369
lines changed

10 files changed

+480
-369
lines changed

Cargo.lock

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contract/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ near-contract-standards = "4.1.1"
1414
uint = { version = "0.9.3", default-features = false }
1515
ed25519-dalek = "1.0.1"
1616
near-self-update = { git = "https://github.com/sweatco/near-self-update.git", rev = "7064db3cdd924efc7fa7c00664920a2b482e7bcf" }
17+
18+
[dev-dependencies]
19+
rand = "0.7.0"
20+
sha256 = "1.3.0"
21+
crypto-hash = "0.3"
22+
fake = "2.8.0"
23+
base64 = "0.21.3"

contract/src/common.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ impl<'de> Deserialize<'de> for U32 {
8686

8787
#[cfg(test)]
8888
pub(crate) mod tests {
89-
use std::time::Duration;
89+
use std::{collections::HashSet, time::Duration};
9090

9191
use near_sdk::{test_utils::VMContextBuilder, testing_env, AccountId, Balance};
9292

93-
use crate::{common::UDecimal, Contract};
93+
use crate::{common::UDecimal, jar::model::Jar, product::model::Product, Contract};
9494

9595
pub(crate) struct Context {
9696
pub contract: Contract,
97+
pub owner: AccountId,
9798
ft_contract_id: AccountId,
98-
owner: AccountId,
9999
builder: VMContextBuilder,
100100
}
101101

@@ -124,6 +124,33 @@ pub(crate) mod tests {
124124
}
125125
}
126126

127+
pub(crate) fn with_products(mut self, products: &[Product]) -> Self {
128+
for product in products {
129+
self.contract.products.insert(product.id.clone(), product.clone());
130+
}
131+
132+
self
133+
}
134+
135+
pub(crate) fn with_jars(mut self, jars: &[Jar]) -> Self {
136+
for jar in jars {
137+
self.contract.jars.push(jar.clone());
138+
139+
let account_id = &jar.account_id;
140+
if !self.contract.account_jars.contains_key(account_id) {
141+
self.contract.account_jars.insert(account_id.clone(), HashSet::new());
142+
}
143+
144+
self.contract
145+
.account_jars
146+
.get_mut(account_id)
147+
.unwrap()
148+
.insert(jar.index);
149+
}
150+
151+
self
152+
}
153+
127154
pub(crate) fn set_block_timestamp_in_days(&mut self, days: u64) {
128155
self.set_block_timestamp(Duration::from_secs(days * 24 * 60 * 60));
129156
}
@@ -156,7 +183,7 @@ pub(crate) mod tests {
156183
self.switch_account(&self.ft_contract_id.clone());
157184
}
158185

159-
pub(crate) fn with_deposit_yocto(&mut self, amount: Balance, f: fn(&mut Context) -> ()) {
186+
pub(crate) fn with_deposit_yocto(&mut self, amount: Balance, f: impl FnOnce(&mut Context)) {
160187
self.set_deposit_yocto(amount);
161188

162189
f(self);

0 commit comments

Comments
 (0)