|
17 | 17 | use crate::{mock::*, Error, IDGraph, Identity, IdentityContext, IdentityStatus, Web3Network};
|
18 | 18 | use frame_support::{assert_err, assert_noop, assert_ok, traits::Get};
|
19 | 19 | use sp_runtime::AccountId32;
|
20 |
| - |
21 | 20 | pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]);
|
22 | 21 | pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
|
23 | 22 | pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]);
|
@@ -422,14 +421,76 @@ fn get_id_graph_works() {
|
422 | 421 | let id_graph = IMT::get_id_graph(&who);
|
423 | 422 | assert_eq!(id_graph.len(), 22);
|
424 | 423 |
|
425 |
| - // index 0 has the oldest identity |
426 | 424 | assert_eq!(id_graph.get(0).unwrap().0, who);
|
427 | 425 |
|
428 | 426 | // index 21 has the newest identity
|
429 | 427 | assert_eq!(id_graph.get(21).unwrap().0, alice_twitter_identity(21));
|
430 | 428 | });
|
431 | 429 | }
|
432 | 430 |
|
| 431 | +#[test] |
| 432 | +fn get_id_graph_identities_within_same_block() { |
| 433 | + new_test_ext().execute_with(|| { |
| 434 | + let who: Identity = ALICE.into(); |
| 435 | + System::set_block_number(1); |
| 436 | + |
| 437 | + let identities = vec![ |
| 438 | + (alice_twitter_identity(1), vec![]), |
| 439 | + (alice_substrate_identity(), vec![Web3Network::LitentryRococo]), |
| 440 | + (alice_evm_identity(), vec![Web3Network::Ethereum]), |
| 441 | + (bob_substrate_identity(), vec![Web3Network::Litentry]), |
| 442 | + ]; |
| 443 | + |
| 444 | + for (identity, networks) in identities { |
| 445 | + assert_ok!(IMT::link_identity( |
| 446 | + RuntimeOrigin::signed(ALICE), |
| 447 | + who.clone(), |
| 448 | + identity, |
| 449 | + networks, |
| 450 | + )); |
| 451 | + } |
| 452 | + |
| 453 | + let id_graph = IMT::get_id_graph(&who); |
| 454 | + let sorted_identities = [ |
| 455 | + alice_evm_identity(), |
| 456 | + who.clone(), |
| 457 | + bob_substrate_identity(), |
| 458 | + alice_substrate_identity(), |
| 459 | + alice_twitter_identity(1), |
| 460 | + ]; |
| 461 | + |
| 462 | + for (i, identity) in sorted_identities.iter().enumerate() { |
| 463 | + assert_eq!(&id_graph.get(i).unwrap().0, identity); |
| 464 | + } |
| 465 | + |
| 466 | + // clear all identites |
| 467 | + assert_ok!(IMT::remove_identity(RuntimeOrigin::signed(ALICE), who.clone(), vec![],)); |
| 468 | + |
| 469 | + // change order of the identites |
| 470 | + let identities = vec![ |
| 471 | + (bob_substrate_identity(), vec![Web3Network::Litentry]), |
| 472 | + (alice_substrate_identity(), vec![Web3Network::LitentryRococo]), |
| 473 | + (alice_twitter_identity(1), vec![]), |
| 474 | + (alice_evm_identity(), vec![Web3Network::Ethereum]), |
| 475 | + ]; |
| 476 | + |
| 477 | + for (identity, networks) in identities { |
| 478 | + assert_ok!(IMT::link_identity( |
| 479 | + RuntimeOrigin::signed(ALICE), |
| 480 | + who.clone(), |
| 481 | + identity, |
| 482 | + networks, |
| 483 | + )); |
| 484 | + } |
| 485 | + |
| 486 | + let id_graph = IMT::get_id_graph(&who); |
| 487 | + |
| 488 | + for (i, identity) in sorted_identities.iter().enumerate() { |
| 489 | + assert_eq!(&id_graph.get(i).unwrap().0, identity); |
| 490 | + } |
| 491 | + }); |
| 492 | +} |
| 493 | + |
433 | 494 | #[test]
|
434 | 495 | fn id_graph_stats_works() {
|
435 | 496 | new_test_ext().execute_with(|| {
|
|
0 commit comments