Skip to content

Commit

Permalink
chore: add OwnerShipTransferred unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dandheedge committed Oct 3, 2023
1 parent 8e054c9 commit c6017db
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/handlers/OwnershipTransferred.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { beforeEach, describe, expect, test, vi } from 'vitest';

import OwnerShipTransferred from '../../src/handlers/OwnershipTransferred';
import { block, ctx, logs } from '../stubs/params';

vi.mock('../../src/model/', async (importOriginal) => {
const actualMods = await importOriginal;
const Application = vi.fn();
return {
...actualMods!,
Application,
};
});

describe('ApplicationCreated', () => {
let ownershipTransferred: OwnerShipTransferred;
const mockApplicationStorage = new Map();
beforeEach(() => {
ownershipTransferred = new OwnerShipTransferred(mockApplicationStorage);
mockApplicationStorage.clear();
vi.clearAllMocks();
});
describe('handle', async () => {
test('call with correct params', async () => {
vi.spyOn(ownershipTransferred, 'handle');
ownershipTransferred.handle(logs[2], block, ctx);
expect(ownershipTransferred.handle).toHaveBeenCalledWith(
logs[2],
block,
ctx,
);
});
test('wrong contract address', async () => {
await ownershipTransferred.handle(logs[0], block, ctx);
expect(mockApplicationStorage.size).toBe(0);
});
test('Ownership Transferred', async () => {
const mockApplicationStorage2 = new Map();
const appId = logs[2].transaction.to;
mockApplicationStorage2.set(appId, {
id: appId,
owner: '0xf05d57a5bed2d1b529c56001fc5810cc9afc0335',
factory: {
id: '0x7122cd1221c20892234186facfe8615e6743ab02',
},
});
const ownerMock = new OwnerShipTransferred(mockApplicationStorage2);
await ownerMock.handle(logs[2], block, ctx);
expect(mockApplicationStorage2.get(appId).owner).not.toBe(
'0xf05d57a5bed2d1b529c56001fc5810cc9afc0335',
);
});
});
});
38 changes: 38 additions & 0 deletions tests/stubs/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const logs = [
id: '0004411683-000001-cae3a',
transactionIndex: 1,
from: '0x74d093f6911ac080897c3145441103dabb869307',
to: '0x95ff8d3ce9dcb7455beb7845143bea84fe5c4f6f',
hash: '0x1b165c2cd18cc58823fbe598e954458774a48f69249efed9ba5cf243b17d0d89',
chainId: 11155111,
value: '0',
Expand Down Expand Up @@ -120,6 +121,43 @@ export const logs = [
},
},
},
{
id: '0004412547-000071-ef8d2',
logIndex: 71,
transactionIndex: 38,
address: '0x5a1651482b751c1ecc36acb2fff5f31df24e7683',
topics: [
'0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0',
'0x0000000000000000000000000000000000000000000000000000000000000000',
'0x00000000000000000000000096ae2ecbfde74b1ec55e9cf626ee80e4f64c8a63',
],
data: '0x',
block: {
id: '0004412547-ef8d2',
height: 4412547,
hash: '0xef8d2ed24f024c5299be89a8cd518f69944c949f281f675f90aa360d108a2003',
parentHash:
'0xb73623fba8d50070a0f42eb884a8f28fc56a2af336d9721d3e25615d565b3f85',
timestamp: 1696292376000,
},
transaction: {
id: '0004412547-000038-ef8d2',
transactionIndex: 38,
from: '0x96ae2ecbfde74b1ec55e9cf626ee80e4f64c8a63',
to: '0x7122cd1221c20892234186facfe8615e6743ab02',
hash: '0xc4df497a15a4afc64dcdb511be8d282283ddd99fc6b4760c74dbaf0570019aa0',
chainId: 11155111,
value: '0',
block: {
id: '0004412547-ef8d2',
height: 4412547,
hash: '0xef8d2ed24f024c5299be89a8cd518f69944c949f281f675f90aa360d108a2003',
parentHash:
'0xb73623fba8d50070a0f42eb884a8f28fc56a2af336d9721d3e25615d565b3f85',
timestamp: 1696292376000,
},
},
},
];
export const block = {
header: {
Expand Down

0 comments on commit c6017db

Please sign in to comment.