Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: psp22 trait contract example with drink tests #300

Open
wants to merge 178 commits into
base: main
Choose a base branch
from

Conversation

chungquantin
Copy link
Collaborator

@chungquantin chungquantin commented Sep 19, 2024

Description

Example contract for the fungible use case that applies the PSP22 traits from #297. The PR includes:

Daanvdplas and others added 30 commits May 19, 2024 17:38
# This is the 1st commit message:

refactor: general

# This is the commit message #2:

init

# This is the commit message #3:

begin refactor

# This is the commit message #4:

refactor: error handling

# This is the commit message #5:

tests: add error handling tests

# This is the commit message #6:

WIP

# This is the commit message #7:

finalise error handling

# This is the commit message #8:

refactor: easier review
@chungquantin chungquantin changed the base branch from chore/tests_with_drink to main October 3, 2024 06:32
Comment on lines +69 to +78
assert_eq!(
last_contract_event(&session).unwrap(),
Created {
id: TOKEN,
creator: account_id_from_slice(&contract),
admin: account_id_from_slice(&contract),
}
.encode()
.as_slice()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved but not now. Opened an issue: r0gue-io/pop-drink#24

Copy link
Collaborator

@Daanvdplas Daanvdplas Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this improve these assertions a lot (deriving debug and partialeq traits under std feature):

#[ink::event]
#[cfg_attr(feature = "std", derive(Debug, PartialEq))]
pub struct Transfer {
	/// The source of the transfer. `None` when minting.
	#[ink(topic)]
	pub from: Option<AccountId>,
	/// The recipient of the transfer. `None` when burning.
	#[ink(topic)]
	pub to: Option<AccountId>,
	/// The amount transferred (or minted/burned).
	pub value: u128,
}

Is working in the integration tests for me. This gives much clearer errors.

@Daanvdplas Daanvdplas self-requested a review October 20, 2024 09:45
Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed some small changes, lgtm now! Thanks for all the hard work!

pop-api/examples/fungibles/lib.rs Outdated Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Outdated Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Outdated Show resolved Hide resolved
pop-api/src/v0/fungibles/errors.rs Outdated Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
pop-api/examples/fungibles/lib.rs Show resolved Hide resolved
@@ -108,9 +108,9 @@ impl From<StatusCode> for Psp22Error {
let encoded = value.0.to_le_bytes();
match encoded {
// BalanceLow.
[3, ASSETS, 0, _] => Psp22Error::InsufficientBalance,
[_, ASSETS, 0, _] => Psp22Error::InsufficientBalance,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this 3 and not change it to MODULE_ERROR?

@chungquantin chungquantin force-pushed the chungquantin/feat-psp22_example branch from 447f1b4 to 411ff66 Compare October 31, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Pop API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants