Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wide-islands-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@human-protocol/sdk": minor
"@human-protocol/python-sdk": minor
---

Add cancellationRequestedAt field to Escrow data model
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class EscrowData:
token (str): Address of the payment token.
total_funded_amount (int): Total amount funded to the escrow.
created_at (int): Creation timestamp in milliseconds.
cancellation_requested_at (Optional[int]): Cancellation request timestamp in
milliseconds.
chain_id (ChainId): Chain where the escrow is deployed.
"""

Expand All @@ -86,6 +88,7 @@ def __init__(
token: str,
total_funded_amount: str,
created_at: str,
cancellation_requested_at: Optional[str] = None,
final_results_url: Optional[str] = None,
final_results_hash: Optional[str] = None,
intermediate_results_url: Optional[str] = None,
Expand Down Expand Up @@ -129,6 +132,11 @@ def __init__(
self.token = token
self.total_funded_amount = int(total_funded_amount)
self.created_at = int(created_at) * 1000
self.cancellation_requested_at = (
int(cancellation_requested_at) * 1000
if cancellation_requested_at is not None
else None
)
self.chain_id = chain_id


Expand Down Expand Up @@ -325,6 +333,7 @@ def get_escrows(
token=escrow.get("token"),
total_funded_amount=escrow.get("totalFundedAmount"),
created_at=escrow.get("createdAt"),
cancellation_requested_at=escrow.get("cancellationRequestedAt"),
final_results_url=escrow.get("finalResultsUrl"),
final_results_hash=escrow.get("finalResultsHash"),
intermediate_results_url=escrow.get("intermediateResultsUrl"),
Expand Down Expand Up @@ -423,6 +432,7 @@ def get_escrow(
token=escrow.get("token"),
total_funded_amount=escrow.get("totalFundedAmount"),
created_at=escrow.get("createdAt"),
cancellation_requested_at=escrow.get("cancellationRequestedAt"),
final_results_url=escrow.get("finalResultsUrl"),
final_results_hash=escrow.get("finalResultsHash"),
intermediate_results_url=escrow.get("intermediateResultsUrl"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
token
totalFundedAmount
createdAt
cancellationRequestedAt
}
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_get_escrows(self):
"token": "0x1234567890123456789012345678901234567891",
"totalFundedAmount": "1000000000000000000",
"createdAt": "1683811973",
"cancellationRequestedAt": "1683812000",
}

def side_effect(subgraph_url, query, params, options):
Expand Down Expand Up @@ -134,6 +135,10 @@ def side_effect(subgraph_url, query, params, options):
self.assertEqual(
int(filtered[0].created_at), int(mock_escrow["createdAt"]) * 1000
)
self.assertEqual(
int(filtered[0].cancellation_requested_at),
int(mock_escrow["cancellationRequestedAt"]) * 1000,
)

filter = EscrowFilter(chain_id=ChainId.POLYGON_AMOY)

Expand Down Expand Up @@ -184,6 +189,7 @@ def test_get_escrows_with_status_array(self):
"token": "0x1234567890123456789012345678901234567891",
"totalFundedAmount": "1000000000000000000",
"createdAt": "1672531200000",
"cancellationRequestedAt": None,
}
mock_escrow_2 = {
"id": "0x1234567890123456789012345678901234567891",
Expand All @@ -204,6 +210,7 @@ def test_get_escrows_with_status_array(self):
"token": "0x1234567890123456789012345678901234567891",
"totalFundedAmount": "1000000000000000000",
"createdAt": "1672531200000",
"cancellationRequestedAt": None,
}

def side_effect(subgraph_url, query, params, options):
Expand Down Expand Up @@ -239,6 +246,8 @@ def side_effect(subgraph_url, query, params, options):
self.assertEqual(len(filtered), 2)
self.assertEqual(filtered[0].address, mock_escrow_1["address"])
self.assertEqual(filtered[1].address, mock_escrow_2["address"])
self.assertIsNone(filtered[0].cancellation_requested_at)
self.assertIsNone(filtered[1].cancellation_requested_at)

def test_get_escrow(self):
with patch(
Expand Down Expand Up @@ -268,6 +277,7 @@ def test_get_escrow(self):
"token": "0x1234567890123456789012345678901234567891",
"totalFundedAmount": "1000000000000000000",
"createdAt": "1683813973",
"cancellationRequestedAt": "1683814000",
}

mock_function.return_value = {
Expand Down Expand Up @@ -326,6 +336,10 @@ def test_get_escrow(self):
self.assertEqual(
int(escrow.created_at), int(mock_escrow["createdAt"]) * 1000
)
self.assertEqual(
int(escrow.cancellation_requested_at),
int(mock_escrow["cancellationRequestedAt"]) * 1000,
)

def test_get_escrow_empty_data(self):
with patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ function mapEscrow(e: EscrowData, chainId: ChainId | number): IEscrow {
token: e.token,
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
chainId: Number(chainId),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ESCROW_FRAGMENT = gql`
token
totalFundedAmount
createdAt
cancellationRequestedAt
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type EscrowData = {
token: string;
totalFundedAmount: string;
createdAt: string;
cancellationRequestedAt: string | null;
};

export type WorkerData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface IEscrow {
token: string;
totalFundedAmount: bigint;
createdAt: number;
cancellationRequestedAt: number | null;
chainId: number;
}

Expand Down
30 changes: 30 additions & 0 deletions packages/sdk/typescript/human-protocol-sdk/test/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3472,6 +3472,7 @@ describe('EscrowUtils', () => {
token: '0x0',
totalFundedAmount: '3',
createdAt: '1',
cancellationRequestedAt: '2',
finalResultsHash: null,
finalResultsUrl: null,
intermediateResultsHash: null,
Expand All @@ -3498,6 +3499,7 @@ describe('EscrowUtils', () => {
token: '0x0',
totalFundedAmount: '3',
createdAt: '1',
cancellationRequestedAt: null,
finalResultsHash: null,
finalResultsUrl: null,
intermediateResultsHash: null,
Expand Down Expand Up @@ -3529,6 +3531,9 @@ describe('EscrowUtils', () => {
count: Number(e.count),
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
recordingOracleFee: e.recordingOracleFee
? Number(e.recordingOracleFee)
: null,
Expand Down Expand Up @@ -3570,6 +3575,7 @@ describe('EscrowUtils', () => {
balance: '0',
count: '1',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Pending',
Expand All @@ -3596,6 +3602,7 @@ describe('EscrowUtils', () => {
balance: '0',
count: '1',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Complete',
Expand Down Expand Up @@ -3632,6 +3639,9 @@ describe('EscrowUtils', () => {
count: Number(e.count),
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
recordingOracleFee: e.recordingOracleFee
? Number(e.recordingOracleFee)
: null,
Expand All @@ -3656,6 +3666,7 @@ describe('EscrowUtils', () => {
balance: '0',
count: '1',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Completed',
Expand Down Expand Up @@ -3692,6 +3703,9 @@ describe('EscrowUtils', () => {
count: Number(e.count),
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
recordingOracleFee: e.recordingOracleFee
? Number(e.recordingOracleFee)
: null,
Expand All @@ -3717,6 +3731,7 @@ describe('EscrowUtils', () => {
count: '1',
jobRequesterId: '1',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Completed',
Expand Down Expand Up @@ -3752,6 +3767,9 @@ describe('EscrowUtils', () => {
count: Number(e.count),
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
recordingOracleFee: e.recordingOracleFee
? Number(e.recordingOracleFee)
: null,
Expand All @@ -3776,6 +3794,7 @@ describe('EscrowUtils', () => {
balance: '0',
count: '1',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Completed',
Expand All @@ -3802,6 +3821,7 @@ describe('EscrowUtils', () => {
balance: '3',
count: '2',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Pending',
Expand Down Expand Up @@ -3840,6 +3860,9 @@ describe('EscrowUtils', () => {
count: Number(e.count),
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
recordingOracleFee: e.recordingOracleFee
? Number(e.recordingOracleFee)
: null,
Expand Down Expand Up @@ -3881,6 +3904,7 @@ describe('EscrowUtils', () => {
balance: '0',
count: '1',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Completed',
Expand All @@ -3907,6 +3931,7 @@ describe('EscrowUtils', () => {
balance: '3',
count: '2',
createdAt: '1',
cancellationRequestedAt: null,
factoryAddress: '0x0',
launcher: '0x0',
status: 'Pending',
Expand Down Expand Up @@ -3946,6 +3971,9 @@ describe('EscrowUtils', () => {
count: Number(e.count),
totalFundedAmount: BigInt(e.totalFundedAmount),
createdAt: Number(e.createdAt) * 1000,
cancellationRequestedAt: e.cancellationRequestedAt
? Number(e.cancellationRequestedAt) * 1000
: null,
recordingOracleFee: e.recordingOracleFee
? Number(e.recordingOracleFee)
: undefined,
Expand Down Expand Up @@ -4025,6 +4053,7 @@ describe('EscrowUtils', () => {
manifest: null,
manifestHash: null,
createdAt: '0',
cancellationRequestedAt: '12',
};
const gqlFetchSpy = vi
.spyOn(gqlFetch, 'default')
Expand All @@ -4042,6 +4071,7 @@ describe('EscrowUtils', () => {
reputationOracleFee: 1,
exchangeOracleFee: 1,
createdAt: 0,
cancellationRequestedAt: 12000,
chainId,
jobRequesterId: null,
manifest: null,
Expand Down
1 change: 1 addition & 0 deletions packages/subgraph/human-protocol/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Escrow @entity(immutable: false) {
intermediateResultsHash: String # string
finalResultsUrl: String # string
finalResultsHash: String # string
cancellationRequestedAt: BigInt
jobRequesterId: String # string
createdAt: BigInt!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ export function handleCancellationRequested(
null,
Address.fromBytes(escrowEntity.address)
);
escrowEntity.cancellationRequestedAt = event.block.timestamp;
escrowEntity.status = 'ToCancel';
escrowEntity.save();
statusEventEntity.launcher = escrowEntity.launcher;
Expand Down
6 changes: 6 additions & 0 deletions packages/subgraph/human-protocol/tests/escrow/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,12 @@ describe('Escrow', () => {
assert.fieldEquals('EscrowStatusEvent', id, 'status', 'ToCancel');

// Escrow
assert.fieldEquals(
'Escrow',
escrowAddress.toHex(),
'cancellationRequestedAt',
cancellationRequested.block.timestamp.toString()
);
assert.fieldEquals('Escrow', escrowAddress.toHex(), 'status', 'ToCancel');
assert.fieldEquals(
'Transaction',
Expand Down
Loading