Skip to content

Commit

Permalink
add event and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Sep 7, 2023
1 parent 6207c2c commit 6fb2792
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions contracts/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ mod tests {
use std::ops::Mul;

use cost::MILI_NEAR;
use near_sdk::json_types::Base64VecU8;
use near_sdk::test_utils::{self, VMContextBuilder};
use near_sdk::{testing_env, Balance, Gas, VMContext};
use sbt::*;
Expand Down Expand Up @@ -2693,6 +2694,7 @@ mod tests {
assert_eq!(ctr.sbt_supply_by_class(issuer3(), i), 0);
}
}

#[test]
fn sbt_burn_all_limit() {
let (mut ctx, mut ctr) = setup(&issuer1(), 60 * MINT_DEPOSIT);
Expand Down Expand Up @@ -2743,6 +2745,40 @@ mod tests {
assert_eq!(ctr.sbt_supply(issuer3()), 20);
}

#[test]
fn sbt_update_token_references() {
let (ctx, mut ctr) = setup(&fractal_mainnet(), 2 * MINT_DEPOSIT);
let m1_1 = mk_metadata(1, Some(START));
let tid1 = ctr.sbt_mint(vec![(bob(), vec![m1_1.clone()])])[0];
let tid2 = ctr.sbt_mint(vec![(alice(), vec![m1_1])])[0];

let t1 = ctr.sbt(fractal_mainnet(), tid1).unwrap();
assert_eq!(t1.metadata.reference, Some("abc".to_owned()));

// reset logs
testing_env!(ctx);
let r = Some("ipfs://abc123".to_owned());
let r_hash = Some(Base64VecU8(vec![1, 1, 2]));
ctr.sbt_update_token_references(vec![(tid2, r.clone(), r_hash.clone())]);

let t2 = ctr.sbt(fractal_mainnet(), tid2).unwrap();
assert_eq!(t2.metadata.reference, r);
assert_eq!(t2.metadata.reference_hash, r_hash);

let t1_2 = ctr.sbt(fractal_mainnet(), tid1).unwrap();
assert_eq!(t1, t1_2);

let log = mk_log_str(
"token_reference",
&format!(
r#"{{"issuer":"{}","tokens":[{}]}}"#,
fractal_mainnet(),
tid2
),
);
assert_eq!(test_utils::get_logs(), log);
}

#[test]
fn is_human_call() {
let (mut ctx, mut ctr) = setup(&fractal_mainnet(), MINT_DEPOSIT);
Expand Down
10 changes: 10 additions & 0 deletions contracts/registry/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,12 @@ impl SBTRegistry for Contract {
) {
let issuer = env::predecessor_account_id();
let issuer_id = self.assert_issuer(&issuer);
let mut token_ids = vec![0; updates.len()];
let mut key = IssuerTokenId {
issuer_id,
token: 0,
};
let mut idx = 0;
for (tid, reference, reference_hash) in updates {
key.token = tid;
let mut t = match self.issuer_tokens.get(&key) {
Expand All @@ -468,6 +470,14 @@ impl SBTRegistry for Contract {
m.reference_hash = reference_hash;
t.metadata = m.into();
self.issuer_tokens.insert(&key, &t);
token_ids[idx] = tid;
idx += 1;
}

SbtTokensEvent {
issuer,
tokens: token_ids,
}
.emit_token_reference();
}
}

0 comments on commit 6fb2792

Please sign in to comment.