Skip to content

Commit

Permalink
Merge pull request #1 from overcat/improvements
Browse files Browse the repository at this point in the history
Some Improvements
  • Loading branch information
earrietadev authored Mar 4, 2024
2 parents db9679d + deb1b85 commit 81a221b
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 141 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .git-blame-ignore-revs
# Format code using `cargo fmt`.
dde86e68796841b98931948431fa300db0a9ef91
20 changes: 20 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Rust

on:
push:
pull_request:

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update
- run: cargo fmt --check

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update
- run: cargo test
20 changes: 10 additions & 10 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[workspace]
resolver = "2"

members = [
"registry",
]
members = ["registry"]

[profile.release-with-logs]
inherits = "release"
Expand All @@ -20,4 +18,4 @@ codegen-units = 1
lto = true

[workspace.dependencies.soroban-sdk]
version = "20.3.2"
version = "20.4.0"
11 changes: 8 additions & 3 deletions registry/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ impl RegistryContractTrait for RegistryContract {
panic_with_error!(&e, &ContractErrors::ExpiredDomain);
}

let node_hash: BytesN<32> = generate_node(&e, &sub, &(Bytes::from(domain.node.clone())));
let node_hash: BytesN<32> =
generate_node(&e, &sub, &(Bytes::from(domain.node.clone())));
let record_key: RecordKeys = RecordKeys::SubRecord(node_hash.clone());

e.set_record(&Record::SubDomain(SubDomain {
Expand Down Expand Up @@ -212,7 +213,9 @@ impl RegistryContractTrait for RegistryContract {
Some(Record::Domain(domain))
}
Record::SubDomain(sub) => {
if let Record::Domain(domain) = e.record(&RecordKeys::Record(sub.parent.clone())).unwrap() {
if let Record::Domain(domain) =
e.record(&RecordKeys::Record(sub.parent.clone())).unwrap()
{
if domain.exp_date < e.ledger().timestamp() {
panic_with_error!(&e, &ContractErrors::ExpiredDomain);
}
Expand Down Expand Up @@ -271,7 +274,9 @@ impl RegistryContractTrait for RegistryContract {
);
}
Record::SubDomain(sub) => {
if let Record::Domain(domain) = e.record(&RecordKeys::Record(sub.parent.clone())).unwrap() {
if let Record::Domain(domain) =
e.record(&RecordKeys::Record(sub.parent.clone())).unwrap()
{
domain.owner.require_auth();
} else {
panic_with_error!(&e, &ContractErrors::InvalidParent);
Expand Down
4 changes: 2 additions & 2 deletions registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]

mod contract;
mod storage;
mod errors;
mod storage;
mod tests;
mod utils;
mod tests;
2 changes: 1 addition & 1 deletion registry/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod core;
pub mod record;
pub mod record;
2 changes: 1 addition & 1 deletion registry/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod test_admin;
pub mod test_records;
pub mod test_transfers;
pub mod test_utils;
pub mod test_transfers;
56 changes: 34 additions & 22 deletions registry/src/tests/test_admin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![cfg(test)]

use soroban_sdk::{Bytes, Env, IntoVal, Vec};
use soroban_sdk::testutils::{MockAuth, MockAuthInvoke};
use crate::storage::core::{CoreData, CoreDataEntity};
use crate::tests::test_utils::{create_test_data, init_contract, TestData};
use soroban_sdk::testutils::{MockAuth, MockAuthInvoke};
use soroban_sdk::{Bytes, Env, IntoVal, Vec};

#[test]
pub fn test_updating_tlds() {
Expand All @@ -18,28 +18,40 @@ pub fn test_updating_tlds() {
assert_eq!(core.allowed_tlds, test_data.allowed_tlds);

// It should fail because the admin didn't sign the transaction
assert!(
test_data.contract_client.try_update_tlds(&Vec::from_array(&e, [Bytes::from_slice(&e, "eth".as_bytes())]))
.is_err()
);

test_data.contract_client
.mock_auths(&[
MockAuth {
address: &test_data.adm,
invoke: &MockAuthInvoke {
contract: &test_data.contract_client.address,
fn_name: "update_tlds",
args: (Vec::from_array(&e, [Bytes::from_slice(&e, "eth".as_bytes())]), ).into_val(&e),
sub_invokes: &[],
},
}
])
.update_tlds(&Vec::from_array(&e, [Bytes::from_slice(&e, "eth".as_bytes())]));
assert!(test_data
.contract_client
.try_update_tlds(&Vec::from_array(
&e,
[Bytes::from_slice(&e, "eth".as_bytes())]
))
.is_err());

test_data
.contract_client
.mock_auths(&[MockAuth {
address: &test_data.adm,
invoke: &MockAuthInvoke {
contract: &test_data.contract_client.address,
fn_name: "update_tlds",
args: (Vec::from_array(
&e,
[Bytes::from_slice(&e, "eth".as_bytes())],
),)
.into_val(&e),
sub_invokes: &[],
},
}])
.update_tlds(&Vec::from_array(
&e,
[Bytes::from_slice(&e, "eth".as_bytes())],
));

let updated_core: CoreData = e.as_contract(&test_data.contract_client.address, || {
e.core_data().unwrap()
});

assert_eq!(updated_core.allowed_tlds, Vec::from_array(&e, [Bytes::from_slice(&e, "eth".as_bytes())]));
}
assert_eq!(
updated_core.allowed_tlds,
Vec::from_array(&e, [Bytes::from_slice(&e, "eth".as_bytes())])
);
}
Loading

0 comments on commit 81a221b

Please sign in to comment.