Skip to content

Commit daa823a

Browse files
andreymgntdelabro
authored andcommitted
Add event assertions
1 parent 81d1d23 commit daa823a

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

exercises/ex03-nft/nft/src/tests/unique_assets.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use crate::{tests::mock::*, Error};
22
use frame_support::{assert_noop, assert_ok, error::BadOrigin, BoundedVec};
33

4+
fn last_event() -> Event {
5+
frame_system::Pallet::<TestRuntime>::events()
6+
.pop()
7+
.expect("Event expected")
8+
.event
9+
}
10+
411
mod mint {
512
use super::*;
613

@@ -17,7 +24,14 @@ mod mint {
1724
assert_eq!(details.creator(), ALICE);
1825
assert_eq!(details.metadata(), metadata);
1926
assert_eq!(details.supply, 5);
20-
assert_eq!(NFTs::account(0, ALICE), 5)
27+
assert_eq!(NFTs::account(0, ALICE), 5);
28+
assert_eq!(
29+
last_event(),
30+
Event::NFTs(crate::Event::Created {
31+
creator: ALICE,
32+
asset_id: 0
33+
})
34+
)
2135
})
2236
}
2337

@@ -72,6 +86,16 @@ mod transfer {
7286

7387
assert_eq!(NFTs::account(0, ALICE), minted_amount - transfered_amount);
7488
assert_eq!(NFTs::account(0, BOB), transfered_amount);
89+
90+
assert_eq!(
91+
last_event(),
92+
Event::NFTs(crate::Event::Transferred {
93+
asset_id: 0,
94+
from: ALICE,
95+
to: BOB,
96+
amount: transfered_amount
97+
})
98+
)
7599
})
76100
}
77101

@@ -94,6 +118,16 @@ mod transfer {
94118

95119
assert_eq!(NFTs::account(0, ALICE), 0);
96120
assert_eq!(NFTs::account(0, BOB), minted_amount);
121+
122+
assert_eq!(
123+
last_event(),
124+
Event::NFTs(crate::Event::Transferred {
125+
asset_id: 0,
126+
from: ALICE,
127+
to: BOB,
128+
amount: minted_amount
129+
})
130+
)
97131
})
98132
}
99133

@@ -157,6 +191,15 @@ mod burn {
157191
minted_amount - burned_amount
158192
);
159193
assert_eq!(NFTs::account(0, ALICE), minted_amount - burned_amount);
194+
195+
assert_eq!(
196+
last_event(),
197+
Event::NFTs(crate::Event::Burned {
198+
asset_id: 0,
199+
owner: ALICE,
200+
total_supply: minted_amount - burned_amount
201+
})
202+
)
160203
})
161204
}
162205

@@ -175,6 +218,15 @@ mod burn {
175218

176219
assert_eq!(NFTs::unique_asset(0).unwrap().supply, 0);
177220
assert_eq!(NFTs::account(0, ALICE), 0);
221+
222+
assert_eq!(
223+
last_event(),
224+
Event::NFTs(crate::Event::Burned {
225+
asset_id: 0,
226+
owner: ALICE,
227+
total_supply: 0
228+
})
229+
)
178230
})
179231
}
180232

0 commit comments

Comments
 (0)