Skip to content

Commit 2377fcf

Browse files
Fix job unit tests
1 parent 31f4575 commit 2377fcf

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

tests/unit/test_job.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ def mock_acp_client(self):
3030
client = MagicMock()
3131
base_fare = Fare(
3232
contract_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
33-
decimals=6
33+
decimals=6,
34+
chain_id=8453
3435
)
3536
client.config.base_fare = base_fare
36-
client.contract_client.config.base_fare = base_fare
37+
client.config.chain_id = 8453
38+
client.acp_contract_client.config.base_fare = base_fare
39+
client.acp_contract_client.config.chain_id = 8453
40+
client.contract_client_by_address.return_value.config.base_fare = base_fare
41+
client.contract_client_by_address.return_value.config.chain_id = 8453
3742
# Mock format_amount to return the value directly (for testing)
3843
client.contract_client_by_address.return_value.config.base_fare.format_amount = lambda x: int(
3944
x)
@@ -219,7 +224,7 @@ def test_acp_contract_client_should_return_default_client_when_no_contract_addre
219224

220225
result = basic_job.acp_contract_client
221226

222-
assert result == mock_acp_client.contract_client
227+
assert result == mock_acp_client.acp_contract_client
223228

224229
def test_acp_contract_client_should_find_client_by_address(
225230
self, basic_job, mock_acp_client
@@ -753,6 +758,7 @@ def test_should_approve_and_sign_memo(self, basic_job, mock_acp_client):
753758
# Setup transaction memo
754759
mock_memo = MagicMock(spec=ACPMemo)
755760
mock_memo.id = 999
761+
mock_memo.type = MemoType.MESSAGE
756762
mock_memo.next_phase = ACPJobPhase.TRANSACTION
757763
mock_memo.payable_details = None
758764
basic_job.memos = [mock_memo]
@@ -789,6 +795,7 @@ def test_should_handle_payable_details_with_different_token(
789795
# Setup transaction memo with payable details in different token
790796
mock_memo = MagicMock(spec=ACPMemo)
791797
mock_memo.id = 999
798+
mock_memo.type = MemoType.MESSAGE
792799
mock_memo.next_phase = ACPJobPhase.TRANSACTION
793800
mock_memo.payable_details = {
794801
"amount": "2000000", # 2 USDC
@@ -827,6 +834,7 @@ def test_should_perform_x402_payment_when_is_x402_job(
827834
"""Should call perform_x402_payment when job is x402"""
828835
mock_memo = MagicMock(spec=ACPMemo)
829836
mock_memo.id = 999
837+
mock_memo.type = MemoType.MESSAGE
830838
mock_memo.next_phase = ACPJobPhase.TRANSACTION
831839
mock_memo.payable_details = None
832840
basic_job.memos = [mock_memo]

virtuals_acp/job.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@ def _get_memo_by_id(self, memo_id: int) -> Optional[ACPMemo]:
468468
return next((m for m in self.memos if m.id == memo_id), None)
469469

470470
def deliver(self, deliverable: DeliverablePayload) -> str | None:
471+
if (
472+
self.latest_memo is None
473+
or self.latest_memo.next_phase != ACPJobPhase.EVALUATION
474+
):
475+
raise ValueError("No transaction memo found")
476+
471477
operations: List[OperationPayload] = []
472478

473479
operations.append(
@@ -490,6 +496,12 @@ def deliver_payable(
490496
skip_fee: bool = False,
491497
expired_at: Optional[datetime] = None,
492498
) -> str | None:
499+
if (
500+
self.latest_memo is None
501+
or self.latest_memo.next_phase != ACPJobPhase.EVALUATION
502+
):
503+
raise ValueError("No transaction memo found")
504+
493505
if expired_at is None:
494506
expired_at = datetime.now(timezone.utc) + timedelta(minutes=5)
495507

0 commit comments

Comments
 (0)