Skip to content

Commit

Permalink
fix: resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Sep 13, 2024
1 parent 6f64e6c commit c25a5bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions pop-api/integration-tests/contracts/fungibles/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ink::prelude::vec::Vec;
use pop_api::{
fungibles::{
self as api,
events::{Approved, Created, Destroyed, MetadataCleared, MetadataSet, Transferred},
events::{Approve, Created, Destroyed, MetadataCleared, MetadataSet, Transfer},
},
primitives::TokenId,
StatusCode,
Expand Down Expand Up @@ -64,7 +64,7 @@ mod fungibles {
#[ink(message)]
pub fn transfer(&mut self, token: TokenId, to: AccountId, value: Balance) -> Result<()> {
api::transfer(token, to, value)?;
self.env().emit_event(Transferred {
self.env().emit_event(Transfer {
from: Some(self.env().account_id()),
to: Some(to),
value,
Expand All @@ -83,7 +83,7 @@ mod fungibles {
_data: Vec<u8>,
) -> Result<()> {
api::transfer_from(token, from, to, value)?;
self.env().emit_event(Transferred { from: Some(from), to: Some(to), value });
self.env().emit_event(Transfer { from: Some(from), to: Some(to), value });
Ok(())
}

Expand All @@ -96,7 +96,7 @@ mod fungibles {
) -> Result<()> {
api::approve(token, spender, value)?;
self.env()
.emit_event(Approved { owner: self.env().account_id(), spender, value });
.emit_event(Approve { owner: self.env().account_id(), spender, value });
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions pop-api/integration-tests/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pop_api::fungibles::events::{
Approved, Created, Destroyed, MetadataCleared, MetadataSet, Transferred,
Approve, Created, Destroyed, MetadataCleared, MetadataSet, Transfer,
};
use pop_primitives::{ArithmeticError::*, Error, Error::*, TokenError::*, TokenId};
use utils::*;
Expand Down Expand Up @@ -104,7 +104,7 @@ fn transfer_works() {
// Successfully emit event.
let from = account_id_from_slice(addr.as_ref());
let to = account_id_from_slice(BOB.as_ref());
let expected = Transferred { from: Some(from), to: Some(to), value: amount / 2 }.encode();
let expected = Transfer { from: Some(from), to: Some(to), value: amount / 2 }.encode();
assert_eq!(last_contract_event(), expected.as_slice());
// Transfer token to account that does not exist.
assert_eq!(transfer(&addr, token, FERDIE, amount / 4), Err(Token(CannotCreate)));
Expand Down Expand Up @@ -161,7 +161,7 @@ fn transfer_from_works() {
// Successfully emit event.
let from = account_id_from_slice(ALICE.as_ref());
let to = account_id_from_slice(BOB.as_ref());
let expected = Transferred { from: Some(from), to: Some(to), value: amount / 2 }.encode();
let expected = Transfer { from: Some(from), to: Some(to), value: amount / 2 }.encode();
assert_eq!(last_contract_event(), expected.as_slice());
});
}
Expand Down Expand Up @@ -190,15 +190,15 @@ fn approve_works() {
// Successfully emit event.
let owner = account_id_from_slice(addr.as_ref());
let spender = account_id_from_slice(BOB.as_ref());
let expected = Approved { owner, spender, value: amount }.encode();
let expected = Approve { owner, spender, value: amount }.encode();
assert_eq!(last_contract_event(), expected.as_slice());
// Non-additive, sets new value.
assert_ok!(approve(&addr, token, &BOB, amount / 2));
assert_eq!(Assets::allowance(token, &addr, &BOB), amount / 2);
// Successfully emit event.
let owner = account_id_from_slice(addr.as_ref());
let spender = account_id_from_slice(BOB.as_ref());
let expected = Approved { owner, spender, value: amount / 2 }.encode();
let expected = Approve { owner, spender, value: amount / 2 }.encode();
assert_eq!(last_contract_event(), expected.as_slice());
// Token is not live, i.e. frozen or being destroyed.
assets::start_destroy(&ALICE, token);
Expand Down
8 changes: 4 additions & 4 deletions pop-api/integration-tests/src/fungibles/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,8 @@ pub(super) fn last_contract_event() -> Vec<u8> {
let contract_events = events
.iter()
.filter_map(|event| match event {
pallet_contracts::Event::<Runtime>::ContractEmitted { data, .. } => {
Some(data.as_slice())
},
pallet_contracts::Event::<Runtime>::ContractEmitted { data, .. } =>
Some(data.as_slice()),
_ => None,
})
.collect::<Vec<&[u8]>>();
Expand All @@ -372,7 +371,8 @@ pub(super) fn last_contract_event() -> Vec<u8> {

/// Decodes a byte slice into an `AccountId` as defined in `primitives`.
///
/// This is used to resolve type mismatches between the `AccountId` in the integration tests and the contract environment.
/// This is used to resolve type mismatches between the `AccountId` in the integration tests and the
/// contract environment.
pub fn account_id_from_slice(s: &[u8; 32]) -> pop_api::primitives::AccountId {
pop_api::primitives::AccountId::decode(&mut &s[..]).expect("Should be decoded to AccountId")
}
4 changes: 2 additions & 2 deletions pop-api/src/v0/fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub mod events {

/// Event emitted when allowance by `owner` to `spender` changes.
#[ink::event]
pub struct Approved {
pub struct Approve {
/// The owner providing the allowance.
#[ink(topic)]
pub owner: AccountId,
Expand All @@ -88,7 +88,7 @@ pub mod events {

/// Event emitted when transfer of tokens occurs.
#[ink::event]
pub struct Transferred {
pub struct Transfer {
/// The source of the transfer. `None` when minting.
#[ink(topic)]
pub from: Option<AccountId>,
Expand Down

0 comments on commit c25a5bd

Please sign in to comment.