-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add OwnerShipTransferred unit test
- Loading branch information
1 parent
caeccdb
commit 9bb2c7f
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters