Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mfornet committed Mar 10, 2021
1 parent 80ed2cf commit a27ca86
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 52 deletions.
74 changes: 60 additions & 14 deletions bridge-token-factory/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions bridge-token-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ panic = "abort"
overflow-checks = true

[dependencies]
near-sdk = { git = "https://github.com/near/near-sdk-rs", rev = "af0e826f916f3aa3ea51e8b675ecebdd37176671" }
near-contract-standards = { git = "https://github.com/near/near-sdk-rs", rev = "af0e826f916f3aa3ea51e8b675ecebdd37176671" }
near-sdk = { git = "https://github.com/near/near-sdk-rs", rev = "613adcab6322e4f830efb4d5bde2a810ae642158" }
near-contract-standards = { git = "https://github.com/near/near-sdk-rs", rev = "613adcab6322e4f830efb4d5bde2a810ae642158" }
#near-sdk = { path = "../../near-sdk-rs/near-sdk" }
#near-contract-standards = { path = "../../near-sdk-rs/near-contract-standards" }
serde = { version = "*", features = ["derive"] }
serde_json = "*"
uint = { version = "0.8.3", default-features = false }
Expand All @@ -31,7 +33,8 @@ hex = "0.4.2"
tiny-keccak = "1.4.0"

[dev-dependencies]
near-sdk-sim = { git = "https://github.com/near/near-sdk-rs", rev = "af0e826f916f3aa3ea51e8b675ecebdd37176671" }
near-sdk-sim = { git = "https://github.com/near/near-sdk-rs", rev = "613adcab6322e4f830efb4d5bde2a810ae642158" }
#near-sdk-sim = { path = "../../near-sdk-rs/near-sdk-sim" }
test-token = { git = "https://github.com/mfornet/contracts" }
bridge-token = { path = "../bridge-token" }
mock-prover = { path = "../mock-prover" }
Expand Down
12 changes: 4 additions & 8 deletions bridge-token-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,18 @@ impl BridgeTokenFactory {
assert_self();
assert!(verification_success, "Failed to verify the proof");

let initial_storage_usage = env::storage_usage();
self.record_proof(&proof);
let storage_used = env::storage_usage() - initial_storage_usage;
let balance_required = storage_used as u128 * STORAGE_PRICE_PER_BYTE;
let required_deposit = self.record_proof(&proof);

assert!(
env::attached_deposit()
>= balance_required + self.bridge_token_storage_deposit_required
>= required_deposit + self.bridge_token_storage_deposit_required
);

ext_bridge_token::mint(
new_owner_id,
amount.into(),
&self.get_bridge_token_account_id(token),
env::attached_deposit() - balance_required,
env::attached_deposit() - required_deposit,
env::prepaid_gas() / 2,
);
}
Expand Down Expand Up @@ -351,10 +348,9 @@ impl BridgeTokenFactory {
);
self.used_events.insert(&key);
let current_storage = env::storage_usage();
let attached_deposit = env::attached_deposit();
let required_deposit =
Balance::from(current_storage - initial_storage) * STORAGE_PRICE_PER_BYTE;
attached_deposit - required_deposit
required_deposit
}
}

Expand Down
Loading

0 comments on commit a27ca86

Please sign in to comment.