-
Notifications
You must be signed in to change notification settings - Fork 34
Add reward_override_entity_key to subscriber mapping activity #1003
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
Changes from all commits
a49987b
62f4cb4
958a86f
e6cbd2d
ec39216
5b08bfc
c915620
eb61af8
a1e3bfb
6190c9a
27b217e
98155b6
70d1262
b94539f
0b24593
1b06669
6a3fd6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE IF EXISTS subscriber_mapping_activity ADD COLUMN IF NOT EXISTS reward_override_entity_key TEXT; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,34 @@ async fn test_mapper_rewards(pool: PgPool) -> anyhow::Result<()> { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[sqlx::test] | ||
| async fn reward_mapper_check_entity_key_db(pool: PgPool) { | ||
| let reward_info = reward_info_24_hours(); | ||
| // seed db | ||
| let mut txn = pool.clone().begin().await.unwrap(); | ||
| seed_mapping_data(reward_info.epoch_period.end, &mut txn) | ||
| .await | ||
| .unwrap(); | ||
| txn.commit().await.expect("db txn failed"); | ||
|
|
||
| let rewardable_mapping_activity = subscriber_mapping_activity::db::rewardable_mapping_activity( | ||
| &pool, | ||
| &reward_info.epoch_period, | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| let sub_map = rewardable_mapping_activity.as_keyed_map(); | ||
| let sub_1 = sub_map.get(SUBSCRIBER_1).expect("sub 1"); | ||
| let sub_3 = sub_map.get(SUBSCRIBER_3).expect("sub 3"); | ||
|
|
||
| assert!(sub_1.reward_override_entity_key.is_none()); | ||
| assert_eq!( | ||
| sub_3.reward_override_entity_key, | ||
| Some("entity key".to_string()) | ||
| ); | ||
|
||
| } | ||
|
|
||
| async fn seed_mapping_data( | ||
| ts: DateTime<Utc>, | ||
| txn: &mut Transaction<'_, Postgres>, | ||
|
|
@@ -84,27 +112,31 @@ async fn seed_mapping_data( | |
| discovery_reward_shares: 30, | ||
| verification_reward_shares: 0, | ||
| carrier_pub_key: PublicKeyBinary::from_str(HOTSPOT_1).unwrap(), | ||
| reward_override_entity_key: None, | ||
| }, | ||
| SubscriberMappingActivity { | ||
| received_timestamp: ts - ChronoDuration::hours(2), | ||
| subscriber_id: SUBSCRIBER_1.to_string().encode_to_vec(), | ||
| discovery_reward_shares: 30, | ||
| verification_reward_shares: 0, | ||
| carrier_pub_key: PublicKeyBinary::from_str(HOTSPOT_1).unwrap(), | ||
| reward_override_entity_key: None, | ||
| }, | ||
| SubscriberMappingActivity { | ||
| received_timestamp: ts - ChronoDuration::hours(1), | ||
| subscriber_id: SUBSCRIBER_2.to_string().encode_to_vec(), | ||
| discovery_reward_shares: 30, | ||
| verification_reward_shares: 0, | ||
| carrier_pub_key: PublicKeyBinary::from_str(HOTSPOT_1).unwrap(), | ||
| reward_override_entity_key: None, | ||
| }, | ||
| SubscriberMappingActivity { | ||
| received_timestamp: ts - ChronoDuration::hours(1), | ||
| subscriber_id: SUBSCRIBER_3.to_string().encode_to_vec(), | ||
| discovery_reward_shares: 30, | ||
| verification_reward_shares: 0, | ||
| carrier_pub_key: PublicKeyBinary::from_str(HOTSPOT_1).unwrap(), | ||
| reward_override_entity_key: Some("entity key".to_string()), | ||
| }, | ||
| ]; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider using report.reward_override_entity_key.trim().is_empty() to also handle cases where the string may contain only whitespace.