diff --git a/abis/MockStaking.abi.json b/abis/MockStaking.abi.json index 182d646..44390bd 100644 --- a/abis/MockStaking.abi.json +++ b/abis/MockStaking.abi.json @@ -1,75 +1,130 @@ [ { "inputs": [ - { - "internalType": "address", - "name": "_token", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_allocationID", - "type": "address" - }, - { - "internalType": "address", - "name": "_indexer", - "type": "address" - } + { + "internalType": "bytes32", + "name": "_subgraphDeploymentID", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_tokens", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_allocationID", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_metadata", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "_proof", + "type": "bytes" + } ], "name": "allocate", "outputs": [], "stateMutability": "nonpayable", "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_tokens", - "type": "uint256" }, { - "internalType": "address", - "name": "_allocationID", - "type": "address" - } - ], - "name": "collect", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "inputs": [ + { + "internalType": "uint256", + "name": "_tokens", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_allocationID", + "type": "address" + } + ], + "name": "collect", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { - "internalType": "address", - "name": "_allocationID", - "type": "address" - } - ], - "name": "getAllocation", - "outputs": [ + "inputs": [ + { + "internalType": "address", + "name": "_allocationID", + "type": "address" + } + ], + "name": "getAllocation", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "indexer", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_subgraphDeploymentID", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_tokens", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_allocationID", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_metadata", + "type": "bytes32" + } + ], + "internalType": "struct IStaking.Allocation", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, { - "components": [ + "inputs": [ { "internalType": "address", - "name": "indexer", + "name": "_assetHolder", "type": "address" + }, + { + "internalType": "bool", + "name": "_allowed", + "type": "bool" } ], - "internalType": "struct IStaking.Allocation", - "name": "", - "type": "tuple" + "name": "setAssetHolder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_tokens", + "type": "uint256" + } + ], + "name": "stake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" } - ], - "stateMutability": "view", - "type": "function" - } ] \ No newline at end of file diff --git a/schema.graphql b/schema.graphql index ebe2b4d..c2cba03 100644 --- a/schema.graphql +++ b/schema.graphql @@ -27,6 +27,7 @@ type Receiver @entity { type Transaction @entity{ id: ID! + transactionGroupID: String! type: String! sender: Sender! receiver: Receiver! diff --git a/src/mappings/escrow.ts b/src/mappings/escrow.ts index 9ca745b..f4aae35 100644 --- a/src/mappings/escrow.ts +++ b/src/mappings/escrow.ts @@ -32,7 +32,7 @@ export function handleCancelThaw(event: CancelThaw): void { } export function handleDeposit(event: Deposit): void { - let transaction = new Transaction(event.transaction.hash.toHexString()) + let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString()) let sender = createOrLoadSender(event.params.sender.toHexString()) let receiver = createOrLoadReceiver(event.params.receiver.toHexString()) let escrow = createOrLoadEscrowAccount(event.params.sender.toHexString(), event.params.receiver.toHexString()) @@ -44,13 +44,14 @@ export function handleDeposit(event: Deposit): void { transaction.receiver = receiver.id transaction.amount = event.params.amount transaction.escrowAccount = escrow.id + transaction.transactionGroupID = event.transaction.hash.toHexString() transaction.save() escrow.save() } export function handleWidthrawals(event: Withdraw): void { - let transaction = new Transaction(event.transaction.hash.toHexString()) + let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString()) let sender = createOrLoadSender(event.params.sender.toHexString()) let receiver = createOrLoadReceiver(event.params.receiver.toHexString()) let escrow = createOrLoadEscrowAccount(event.params.sender.toHexString(), event.params.receiver.toHexString()) @@ -64,6 +65,7 @@ export function handleWidthrawals(event: Withdraw): void { transaction.receiver = receiver.id transaction.amount = event.params.amount transaction.escrowAccount = escrow.id + transaction.transactionGroupID = event.transaction.hash.toHexString() transaction.save() escrow.save() @@ -71,7 +73,7 @@ export function handleWidthrawals(event: Withdraw): void { } export function handleRedeems(event: Redeem): void { - let transaction = new Transaction(event.transaction.hash.toHexString()) + let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString()) let sender = createOrLoadSender(event.params.sender.toHexString()) let receiver = createOrLoadReceiver(event.params.receiver.toHexString()) let escrow = createOrLoadEscrowAccount(event.params.sender.toHexString(), event.params.receiver.toHexString()) @@ -84,7 +86,8 @@ export function handleRedeems(event: Redeem): void { transaction.expectedAmount = event.params.expectedAmount transaction.allocationID = event.params.allocationID.toHexString() transaction.escrowAccount = escrow.id - + transaction.transactionGroupID = event.transaction.hash.toHexString() + transaction.save() escrow.save() diff --git a/tests/helpers.py b/tests/helpers.py index b0d01d6..ec210bb 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -114,7 +114,7 @@ def check_subgraph_transaction( ): graphql_query = """ query($id: String!){ - transactions(where: {id: $id}) { + transactions(where: {transactionGroupID: $id}) { amount } } diff --git a/tests/local_contract_calls.py b/tests/local_contract_calls.py index 725448a..8848c4e 100644 --- a/tests/local_contract_calls.py +++ b/tests/local_contract_calls.py @@ -1,16 +1,26 @@ import json import sys import time +import os from eip712.messages import EIP712Message from eth_account.messages import encode_defunct from web3 import Web3 from web3.exceptions import ContractCustomError, ContractLogicError -from helpers import (ALLOCATION_ID, ALLOCATIONID_PK, GATEWAY, RECEIVER, SIGNER, - SIGNER_PK, check_subgraph_escrow_account, - check_subgraph_signer, check_subgraph_transaction, - decode_custom_error, time_remaining) +from helpers import ( + ALLOCATION_ID, + ALLOCATIONID_PK, + GATEWAY, + RECEIVER, + SIGNER, + SIGNER_PK, + check_subgraph_escrow_account, + check_subgraph_signer, + check_subgraph_transaction, + decode_custom_error, + time_remaining, +) # This script will help test that the subgraph is actually catching the required information ESCROW_ADDRESS = sys.argv[1] @@ -95,8 +105,18 @@ class ReceiptAggregateVoucher(EIP712Message): # MOCK STAKING CONTRACT CALLS try: + message_hash = Web3.solidity_keccak( + ["address", "address"], [GATEWAY, ALLOCATION_ID] + ) + + # Convert the hash to the Ethereum specific signature format + eth_signed_message = encode_defunct(hexstr=message_hash.hex()) + + # Sign the message with the private key + signature = w3.eth.account.sign_message(eth_signed_message, private_key=ALLOCATIONID_PK) + arbitraryBytes32 = os.urandom(32) print("Allocate receiver with allocationid") - mockStaking.functions.allocate(ALLOCATION_ID, RECEIVER).transact({"from": GATEWAY}) + mockStaking.functions.allocate(arbitraryBytes32, 1000, ALLOCATION_ID, arbitraryBytes32, RECEIVER).transact({"from": RECEIVER}) except ContractCustomError as e: raise ContractCustomError(decode_custom_error(mockStaking_abi_json, str(e), w3)) except ContractLogicError as e: diff --git a/tests/timeline-aggregation-protocol-contracts b/tests/timeline-aggregation-protocol-contracts index abf58fe..b581f77 160000 --- a/tests/timeline-aggregation-protocol-contracts +++ b/tests/timeline-aggregation-protocol-contracts @@ -1 +1 @@ -Subproject commit abf58fec4092f62f88bce1904ca55b9341443478 +Subproject commit b581f77f7df28c52e7f42705e7aadd0bf58cdebc