Skip to content

Commit

Permalink
Merge pull request #67 from Once-Upon/benguyen0214/ou-1278-add-unit-t…
Browse files Browse the repository at this point in the history
…ests-for-fren-pet-in-context

Add unit test for frenpet
  • Loading branch information
pcowgill authored Dec 7, 2023
2 parents 796e8f1 + d4dee77 commit d259c8a
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/commands/grabTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function registerGrabTransactionCommand() {
console.log(`Fetching transaction from transaction api: ${hash}`);
// grab transaction from api and save it in test/transactions
await grabTx(hash, prefix);
console.log(`Transaction saved to ${txFilePath}.json`);
console.log(`Transaction saved to ${txFilePath}`);
process.exit(0); // Successful exit
} catch (error) {
console.error('Failed to grab the transaction:', error);
Expand Down
27 changes: 27 additions & 0 deletions src/protocol/frenpet/gameplay.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Transaction } from '../../types';
import { detectFrenPet, generateFrenPetContext } from './gameplay';
import { contextSummary } from '../../helpers/utils';
import frenpet0x18a097a8 from '../../test/transactions/frenpet-0x18a097a8.json';
import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json';

describe('Frenpet', () => {
it('Should detect as frenpet', () => {
const frenpet1 = detectFrenPet(frenpet0x18a097a8 as Transaction);
expect(frenpet1).toBe(true);
});

it('Should generate frenpet context', () => {
const frenpet1 = generateFrenPetContext(frenpet0x18a097a8 as Transaction);
expect(frenpet1.context.summaries.en.title).toBe('Fren Pet');
expect(frenpet1.context.summaries.category).toBe('PROTOCOL_1');
const desc1 = contextSummary(frenpet1.context);
expect(desc1).toBe(
'0x30e49549da679ec277301ffe4e66ac76aa1cc413 set pet name for 0x5b51cf49cb48617084ef35e7c7d7a21914769ff1 #13759 to Folded Space NFT #30',
);
});

it('Should not detect as frenpet', () => {
const frenpet1 = detectFrenPet(catchall0xc35c01ac as Transaction);
expect(frenpet1).toBe(false);
});
});
6 changes: 4 additions & 2 deletions src/protocol/frenpet/gameplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const frenPetContextualizer = (
return generateFrenPetContext(transaction);
};

const detectFrenPet = (transaction: Transaction): boolean => {
export const detectFrenPet = (transaction: Transaction): boolean => {
if (
transaction.chainId === 8453 &&
transaction.to === contracts.frenPetGameplayContractV1
Expand All @@ -23,7 +23,9 @@ const detectFrenPet = (transaction: Transaction): boolean => {
};

// Contextualize for mined txs
const generateFrenPetContext = (transaction: Transaction): Transaction => {
export const generateFrenPetContext = (
transaction: Transaction,
): Transaction => {
switch (transaction.sigHash) {
case '0x715488b0': {
// buyAccessory(uint256,uint256)
Expand Down
148 changes: 148 additions & 0 deletions src/test/transactions/frenpet-0x18a097a8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"accessList": [],
"blockHash": "0x87dcd50e7d7671a102c3bafe463101a63747fcc377aa8371204be32f05803a9f",
"blockNumber": 7561419,
"chainId": 8453,
"from": "0x30e49549da679ec277301ffe4e66ac76aa1cc413",
"gas": 43008,
"gasPrice": "6050",
"hash": "0x18a04658b7bf2697bf7ab670a2410e35e87997eacbf97998d4a2a7f7318a97a8",
"input": "0x4d578c9300000000000000000000000000000000000000000000000000000000000035bf00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000014466f6c646564205370616365204e465420233330000000000000000000000000",
"maxFeePerGas": "1500000100",
"maxPriorityFeePerGas": "6000",
"nonce": 2781,
"r": "0xb53ac635e384316e980f43cc66d7512b032c3836f268bcd6f40e7e33f9f483bf",
"s": "0x14d398a724d55c2ec752fa9f150255313b5bd43ace4af5db38a99cc1c6995a92",
"to": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"transactionIndex": 3,
"type": 2,
"v": "0x0",
"value": "0",
"yParity": "0x0",
"delegateCalls": [
{
"action": {
"callType": "delegatecall",
"from": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"gas": "0x3e5e",
"input": "0x4d578c9300000000000000000000000000000000000000000000000000000000000035bf00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000014466f6c646564205370616365204e465420233330000000000000000000000000",
"to": "0xf6b13c270fe21eb9adf17dca5d8222aa2ac225f2",
"value": "0x0"
},
"blockHash": "0x87dcd50e7d7671a102c3bafe463101a63747fcc377aa8371204be32f05803a9f",
"blockNumber": 7561419,
"result": {
"gasUsed": "0x3e5e",
"output": "0x0"
},
"subtraces": 1,
"traceAddress": [
0
],
"transactionHash": "0x18a04658b7bf2697bf7ab670a2410e35e87997eacbf97998d4a2a7f7318a97a8",
"transactionPosition": 3,
"type": "call"
}
],
"baseFeePerGas": 50,
"burntFees": "0",
"minerFees": "258897650",
"transactionFee": "258897650",
"sigHash": "0x4d578c93",
"internalSigHashes": [
{
"from": "0x30e49549da679ec277301ffe4e66ac76aa1cc413",
"to": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"sigHash": "0x4d578c93"
},
{
"from": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"to": "0xf6b13c270fe21eb9adf17dca5d8222aa2ac225f2",
"sigHash": "0x4d578c93"
},
{
"from": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"to": "0x5b51cf49cb48617084ef35e7c7d7a21914769ff1",
"sigHash": "0x6352211e"
}
],
"timestamp": 1701912185,
"isoTimestamp": "2023-12-07T01:23:05.000Z",
"parties": [
"0x30e49549da679ec277301ffe4e66ac76aa1cc413",
"0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"0xf6b13c270fe21eb9adf17dca5d8222aa2ac225f2",
"0x5b51cf49cb48617084ef35e7c7d7a21914769ff1"
],
"receipt": {
"blockHash": "0x87dcd50e7d7671a102c3bafe463101a63747fcc377aa8371204be32f05803a9f",
"blockNumber": 7561419,
"contractAddress": null,
"cumulativeGasUsed": 580833,
"effectiveGasPrice": 6050,
"from": "0x30e49549da679ec277301ffe4e66ac76aa1cc413",
"gasUsed": 42793,
"l1Fee": "0x48267d791c37",
"l1FeeScalar": "0.684",
"l1GasPrice": "0x98901ce52",
"l1GasUsed": "0xb10",
"logsBloom": "0x00000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000008000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000",
"status": true,
"to": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"transactionHash": "0x18a04658b7bf2697bf7ab670a2410e35e87997eacbf97998d4a2a7f7318a97a8",
"transactionIndex": 3,
"type": "0x2"
},
"logs": [
{
"address": "0x0e22b5f3e11944578b37ed04f5312dfc246f443c",
"blockHash": "0x87dcd50e7d7671a102c3bafe463101a63747fcc377aa8371204be32f05803a9f",
"blockNumber": 7561419,
"data": "0x00000000000000000000000000000000000000000000000000000000000035bf00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000014466f6c646564205370616365204e465420233330000000000000000000000000",
"logIndex": 19,
"removed": false,
"topics": [
"0x7e632a301794d8d4a81ea7e20f37d1947158d36e66403af04ba85dd194b66f1b"
],
"transactionHash": "0x18a04658b7bf2697bf7ab670a2410e35e87997eacbf97998d4a2a7f7318a97a8",
"transactionIndex": 3,
"id": "log_08efc831",
"decode": {
"fragment": {
"type": "event",
"inputs": [
{
"name": "tokenId",
"type": "uint256",
"baseType": "uint256",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null
},
{
"name": "name",
"type": "string",
"baseType": "string",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null
}
],
"name": "NameChange",
"anonymous": false
},
"name": "NameChange",
"signature": "NameChange(uint256,string)",
"topic": "0x7e632a301794d8d4a81ea7e20f37d1947158d36e66403af04ba85dd194b66f1b",
"args": [
"13759",
"Folded Space NFT #30"
]
},
"chainId": 8453
}
],
"contractsCreated": []
}

0 comments on commit d259c8a

Please sign in to comment.