Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

carlosvdr
Copy link
Collaborator

@carlosvdr carlosvdr commented Jan 6, 2025

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

@carlosvdr carlosvdr self-assigned this Jan 6, 2025
@coveralls
Copy link

coveralls commented Jan 6, 2025

Pull Request Test Coverage Report for Build 12959664917

Details

  • 310 of 320 (96.88%) changed or added relevant lines in 7 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.5%) to 78.022%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/tap-agent/src/agent/sender_account.rs 2 3 66.67%
crates/tap-agent/src/agent/sender_accounts_manager.rs 2 3 66.67%
crates/tap-agent/src/agent/sender_allocation.rs 98 100 98.0%
crates/tap-agent/src/test.rs 202 208 97.12%
Files with Coverage Reduction New Missed Lines %
crates/tap-agent/src/agent/sender_allocation.rs 4 89.3%
Totals Coverage Status
Change from base Build 12955204222: 0.5%
Covered Lines: 6983
Relevant Lines: 8950

💛 - Coveralls

@carlosvdr carlosvdr requested a review from gusinacio January 6, 2025 16:51
@carlosvdr carlosvdr marked this pull request as ready for review January 13, 2025 19:39
@carlosvdr carlosvdr changed the title Extra tap tests Enhance Test Coverage for Receipt Insertion, Batch Processing, and Sender Accounts” Jan 14, 2025
@carlosvdr carlosvdr changed the title Enhance Test Coverage for Receipt Insertion, Batch Processing, and Sender Accounts” Enhance Test Coverage for Receipt Insertion, Batch Processing, and Sender Accounts Jan 14, 2025
Copy link
Contributor

@suchapalaver suchapalaver left a 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 🙏

suchapalaver
suchapalaver previously approved these changes Jan 14, 2025
@suchapalaver
Copy link
Contributor

@carlosvdr , approving just to remove the block 👍

Copy link
Contributor

@suchapalaver suchapalaver left a 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!

Comment on lines 651 to 676
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()
}
Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

crates/tap-agent/src/tap_agent_test.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/tap_agent_test.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/tap_agent_test.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_accounts_manager.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_accounts_manager.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_account.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_account.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_allocation.rs Outdated Show resolved Hide resolved
Comment on lines 935 to 941
pgpool: PgPool,
sender_aggregator_endpoint: String,
escrow_subgraph_endpoint: &str,
rav_request_receipt_limit: u64,
sender_account: Option<ActorRef<SenderAccountMessage>>,
) -> SenderAllocationArgs {
Copy link
Member

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.

https://bon-rs.com/

Copy link
Member

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.

Copy link
Collaborator Author

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

Copy link
Member

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.

Suggested change
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 {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, no updates here?

@carlosvdr carlosvdr force-pushed the 868b324jv-tap-tests branch from f6dd24e to a0ca003 Compare January 23, 2025 22:15
@carlosvdr carlosvdr requested a review from gusinacio January 23, 2025 22:16
crates/tap-agent/src/agent/sender_account.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_account.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_account.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_account.rs Show resolved Hide resolved
crates/tap-agent/src/agent/sender_account.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_allocation.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_allocation.rs Outdated Show resolved Hide resolved
crates/tap-agent/src/agent/sender_allocation.rs Outdated Show resolved Hide resolved
Comment on lines 984 to 998
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>) {
Copy link
Member

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.

Suggested change
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>) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any updates here?

Comment on lines 935 to 941
pgpool: PgPool,
sender_aggregator_endpoint: String,
escrow_subgraph_endpoint: &str,
rav_request_receipt_limit: u64,
sender_account: Option<ActorRef<SenderAccountMessage>>,
) -> SenderAllocationArgs {
Copy link
Member

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.

Suggested change
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 {

@carlosvdr carlosvdr force-pushed the 868b324jv-tap-tests branch from 78d1b5e to 262efd2 Compare January 24, 2025 18:57
@carlosvdr carlosvdr force-pushed the 868b324jv-tap-tests branch from 262efd2 to 34313f8 Compare January 24, 2025 20:49
@carlosvdr carlosvdr requested a review from gusinacio January 24, 2025 20:51
Copy link
Member

@gusinacio gusinacio left a 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.

Comment on lines +98 to +102
pub static PREFIX_ID: AtomicU32 = AtomicU32::new(0);
let prefix = format!(
"test-{}",
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
);
Copy link
Member

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(&notify).await;
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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())
Copy link
Member

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.

Copy link
Member

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"

Comment on lines +90 to +96
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>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>,
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants