-
Notifications
You must be signed in to change notification settings - Fork 20
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
Enhance Test Coverage for Receipt Insertion, Batch Processing, and Sender Accounts #572
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12959664917Details
💛 - Coveralls |
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.
@carlosvdr can you squash/fix the commit history, please 🙏
e3ef764
to
025024c
Compare
@carlosvdr , approving just to remove the block 👍 |
8140179
to
7930988
Compare
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.
I really want to see what @gusinacio thinks, @carlosvdr!
lazy_static! { | ||
static ref MOCK_EMPTY_ESCROW_SUBGRAPH: OnceCell<Arc<(MockServer, MockGuard)>> = | ||
OnceCell::new(); | ||
} | ||
async fn mock_escrow_subgraph_empty_response() -> Arc<(MockServer, MockGuard)> { | ||
MOCK_EMPTY_ESCROW_SUBGRAPH | ||
.get_or_try_init(|| async { | ||
let mock_ecrow_subgraph_server: MockServer = MockServer::start().await; | ||
let _mock_ecrow_subgraph = mock_ecrow_subgraph_server | ||
.register_as_scoped( | ||
Mock::given(method("POST")) | ||
.and(body_string_contains("TapTransactions")) | ||
.respond_with(ResponseTemplate::new(200).set_body_json( | ||
json!({ "data": { | ||
"transactions": [], | ||
} | ||
}), | ||
)), | ||
) | ||
.await; | ||
Ok::<_, anyhow::Error>(Arc::new((mock_ecrow_subgraph_server, _mock_ecrow_subgraph))) | ||
}) | ||
.await | ||
.unwrap() | ||
.clone() | ||
} |
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.
Hey, I see what you did here, but I think it's not needed to use lazy_static
, since it's used by a single test.
Also, since you are using register_as_scoped
, it doesn't make sense to have a scoped route that is never dropped.
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.
Maybe rstest
is better for this context.
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.
I do agree with you on not using lazy_Static for this and also about the register_as_scoped
Regarding rstest
I think for this specific one, might not be needed since as you said its only used once for one test, could just put it inside the same test actually.
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.
rstest
allow you to "compose" fixtures, which could be nice. But yeah, no worries. I'm just suggesting things in case you want to try it out.
pgpool: PgPool, | ||
sender_aggregator_endpoint: String, | ||
escrow_subgraph_endpoint: &str, | ||
rav_request_receipt_limit: u64, | ||
sender_account: Option<ActorRef<SenderAccountMessage>>, | ||
) -> SenderAllocationArgs { |
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.
This may be a little out of the scope, but one way to make this better is to add bon
and annotate this function with #[bon::builder]
. You are able to set default and only provide member that you actually need to change.
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.
Feel free to use it or not, it's your choice.
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.
Oh yes, I did liked this bon thing
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.
Hey, you didn't use bon here. Add it and provide a default value.
pgpool: PgPool, | |
sender_aggregator_endpoint: String, | |
escrow_subgraph_endpoint: &str, | |
rav_request_receipt_limit: u64, | |
sender_account: Option<ActorRef<SenderAccountMessage>>, | |
) -> SenderAllocationArgs { | |
pgpool: PgPool, | |
sender_aggregator_endpoint: String, | |
escrow_subgraph_endpoint: &str, | |
#[builder(default = 1000)] rav_request_receipt_limit: u64, | |
sender_account: Option<ActorRef<SenderAccountMessage>>, | |
) -> SenderAllocationArgs { |
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.
Hey, no updates here?
f6dd24e
to
a0ca003
Compare
async fn create_sender_allocation( | ||
pgpool: PgPool, | ||
sender_aggregator_endpoint: String, | ||
escrow_subgraph_endpoint: &str, | ||
rav_request_receipt_limit: Option<u64>, | ||
sender_account: Option<ActorRef<SenderAccountMessage>>, | ||
) -> (ActorRef<SenderAllocationMessage>, Arc<Notify>) { |
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.
You can remove all the calls to sender_aggregator_endpoint
that contains DUMMY_URL.
async fn create_sender_allocation( | |
pgpool: PgPool, | |
sender_aggregator_endpoint: String, | |
escrow_subgraph_endpoint: &str, | |
rav_request_receipt_limit: Option<u64>, | |
sender_account: Option<ActorRef<SenderAccountMessage>>, | |
) -> (ActorRef<SenderAllocationMessage>, Arc<Notify>) { | |
async fn create_sender_allocation( | |
pgpool: PgPool, | |
#[builder(default = DUMMY_URL.to_string())] | |
sender_aggregator_endpoint: String, | |
escrow_subgraph_endpoint: &str, | |
rav_request_receipt_limit: Option<u64>, | |
sender_account: Option<ActorRef<SenderAccountMessage>>, | |
) -> (ActorRef<SenderAllocationMessage>, Arc<Notify>) { |
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.
any updates here?
pgpool: PgPool, | ||
sender_aggregator_endpoint: String, | ||
escrow_subgraph_endpoint: &str, | ||
rav_request_receipt_limit: u64, | ||
sender_account: Option<ActorRef<SenderAccountMessage>>, | ||
) -> SenderAllocationArgs { |
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.
Hey, you didn't use bon here. Add it and provide a default value.
pgpool: PgPool, | |
sender_aggregator_endpoint: String, | |
escrow_subgraph_endpoint: &str, | |
rav_request_receipt_limit: u64, | |
sender_account: Option<ActorRef<SenderAccountMessage>>, | |
) -> SenderAllocationArgs { | |
pgpool: PgPool, | |
sender_aggregator_endpoint: String, | |
escrow_subgraph_endpoint: &str, | |
#[builder(default = 1000)] rav_request_receipt_limit: u64, | |
sender_account: Option<ActorRef<SenderAccountMessage>>, | |
) -> SenderAllocationArgs { |
78d1b5e
to
262efd2
Compare
262efd2
to
34313f8
Compare
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.
In general, I can see a great progress here. I think that bon is still new to you but don't forget about defaults, this allows you to provide only what is different from default values.
pub static PREFIX_ID: AtomicU32 = AtomicU32::new(0); | ||
let prefix = format!( | ||
"test-{}", | ||
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst) | ||
); |
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.
Since you are not running in an environment with multiple tests, you can remove the prefix and use None
#[sqlx::test(migrations = "../../migrations")] | ||
async fn test_start_tap_agent(pgpool: PgPool) { | ||
let (prefix, notify, (_actor_ref, _handle)) = start_agent(pgpool.clone()).await; | ||
flush_messages(¬ify).await; |
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.
Do you really need to flush the messages for this test to work?
spawn(..).await
is supposed to wait for all senders and allocations to be created. If it works, maybe you can remove TestableActor.
Mock, MockServer, ResponseTemplate, | ||
}; | ||
|
||
pub static PREFIX_ID: AtomicU32 = AtomicU32::new(0); |
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.
Do you need prefix id here?
|
||
let rav_marked_as_last = sqlx::query!( | ||
r#" | ||
SELECT * FROM scalar_tap_ravs WHERE last = true; |
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.
Could you specify WHERE allocation_id = ALLOCATION_0?
.cast(SenderAccountMessage::UpdateAllocationIds(HashSet::new())) | ||
.unwrap(); | ||
|
||
actor_ref.unwrap().stop_children_and_wait(None, None).await; |
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.
This line kills the children which makes the prior line useless.
I recommend removing this and it should work the same.
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.
Maybe add an assert to check if SenderAllocation actor is stopped.
.pgpool(pgpool.clone()) | ||
.escrow_subgraph_endpoint(&mock_escrow_subgraph_server.uri()) | ||
.sender_account(sender_account) | ||
.sender_aggregator_endpoint(get_grpc_url().await) |
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.
Remove this line
.pgpool(pgpool.clone()) | ||
.escrow_subgraph_endpoint(&mock_escrow_subgraph_server.uri()) | ||
.sender_account(sender_account) | ||
.sender_aggregator_endpoint(get_grpc_url().await) |
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.
Remove
.pgpool(pgpool.clone()) | ||
.escrow_subgraph_endpoint(&mock_escrow_subgraph_server.uri()) | ||
.sender_account(sender_account) | ||
.sender_aggregator_endpoint(get_grpc_url().await) |
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.
Remove
.await; | ||
let (sender_account, notify, prefix, _) = create_sender_account() | ||
.pgpool(pgpool) | ||
.initial_allocation(HashSet::new()) |
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.
If this is the default implementation, you could use default and not provide it here.
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.
same for all arguments that can be "default"
initial_allocation: HashSet<Address>, | ||
rav_request_trigger_value: u128, | ||
max_amount_willing_to_lose_grt: u128, | ||
escrow_subgraph_endpoint: Option<&str>, | ||
network_subgraph_endpoint: Option<&str>, | ||
rav_request_receipt_limit: u64, | ||
aggregator_endpoint: Option<Url>, |
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.
initial_allocation: HashSet<Address>, | |
rav_request_trigger_value: u128, | |
max_amount_willing_to_lose_grt: u128, | |
escrow_subgraph_endpoint: Option<&str>, | |
network_subgraph_endpoint: Option<&str>, | |
rav_request_receipt_limit: u64, | |
aggregator_endpoint: Option<Url>, | |
#[Builder(default = HashSet::new())] | |
initial_allocation: HashSet<Address>, | |
... |
This new tests cover are here to enhance the testing experience and help ensure tap V2 wont affect the processes in a "bigger picture"
As well as added more test types around receiving receipts. For this a new method was added regarding batch inserts for receipts into the DB, trying to be have a more accurate representation of how TAP works on a day to day basis.
Regarding the tests on the "bigger picture" , tests for several layers were added.
Such as a full process from sender account all the way from starting it, creating a sender allocation up to the point of marking allocation as last for redeeming.
Another test added from the sender account manager layer which tries to do the same process as the previous layer but starting from the manager.
And finally a test for the full Tap Agent and simulate as closely as possible the full process of it