generated from Borodutch/smart-contract-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic tests for KetlCred #38
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,156 @@ | ||
import { Feeds, KetlCred, OBSSStorage, Profiles } from '../typechain' | ||
import { MOCK_CID, zeroAddress } from './utils' | ||
import { ethers, upgrades } from 'hardhat' | ||
import { expect } from 'chai' | ||
import { getFakeKetlAttestationContract } from './utils/fakes' | ||
import { version } from '../package.json' | ||
|
||
describe('OBSSStorage: KetlCred', () => { | ||
before(async function () { | ||
this.accounts = await ethers.getSigners() | ||
this.owner = this.accounts[0] | ||
this.user = this.accounts[1] | ||
|
||
this.fakeKetlAttestationContract = await getFakeKetlAttestationContract( | ||
this.owner | ||
) | ||
await this.fakeKetlAttestationContract.mock.balanceOf.returns(1) | ||
await this.fakeKetlAttestationContract.mock.currentTokenId.returns(1) | ||
|
||
this.profilesFactory = await ethers.getContractFactory('Profiles') | ||
this.ketlCredFactory = await ethers.getContractFactory('KetlCred') | ||
this.feedsFactory = await ethers.getContractFactory('Feeds') | ||
this.obssStorageFactory = await ethers.getContractFactory('OBSSStorage') | ||
}) | ||
|
||
describe('grantKetlCred: feedPosts', () => { | ||
beforeEach(async function () { | ||
this.profiles = (await upgrades.deployProxy(this.profilesFactory, [ | ||
this.fakeKetlAttestationContract.address, | ||
0, | ||
this.owner.address, | ||
])) as Profiles | ||
this.ketlCred = (await upgrades.deployProxy( | ||
this.ketlCredFactory, | ||
['Ketl', 'KETL', 0, this.owner.address], | ||
{ | ||
initializer: 'initializeKetlCred', | ||
} | ||
)) as KetlCred | ||
this.feeds = (await upgrades.deployProxy(this.feedsFactory, [ | ||
this.fakeKetlAttestationContract.address, | ||
0, | ||
this.owner.address, | ||
])) as Feeds | ||
this.obssStorage = (await upgrades.deployProxy( | ||
this.obssStorageFactory, | ||
[ | ||
zeroAddress, | ||
version, | ||
this.ketlCred.address, | ||
this.profiles.address, | ||
this.feeds.address, | ||
], | ||
{ | ||
initializer: 'initialize', | ||
} | ||
)) as OBSSStorage | ||
|
||
await this.ketlCred.setAllowedCaller(this.obssStorage.address) | ||
await this.profiles.setAllowedCaller(this.obssStorage.address) | ||
await this.feeds.setAllowedCaller(this.obssStorage.address) | ||
|
||
await this.feeds.addFeed(MOCK_CID) | ||
await this.obssStorage.addFeedPost({ | ||
feedId: 0, | ||
postMetadata: MOCK_CID, | ||
}) | ||
}) | ||
|
||
it('should grant KetlCred when feedPost is upvoted by different user', async function () { | ||
await this.obssStorage.connect(this.user).addFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionType: 1, | ||
}) | ||
expect(await this.ketlCred.balanceOf(this.owner.address)).to.equal(1) | ||
}) | ||
it('should not grant KetlCred when feedPost is downvoted by user', async function () { | ||
await this.obssStorage.connect(this.user).addFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionType: 2, | ||
}) | ||
expect(await this.ketlCred.balanceOf(this.owner.address)).to.equal(0) | ||
}) | ||
it('should not grant KetlCred when feedPost is upvoted by author', async function () { | ||
await this.obssStorage.connect(this.owner).addFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionType: 1, | ||
}) | ||
expect(await this.ketlCred.balanceOf(this.owner.address)).to.equal(0) | ||
}) | ||
it('should not burn KetlCred when upvote is replaced with downvote', async function () { | ||
await this.obssStorage.connect(this.user).addFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionType: 1, | ||
}) | ||
const reactionBefore = await this.feeds.usersToReactions( | ||
0, | ||
0, | ||
0, | ||
this.user.address | ||
) | ||
expect(reactionBefore.reactionType).to.equal(1) | ||
await this.obssStorage.connect(this.user).addFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionType: 2, | ||
}) | ||
const reactionAfter = await this.feeds.usersToReactions( | ||
0, | ||
0, | ||
0, | ||
this.user.address | ||
) | ||
expect(reactionAfter.reactionType).to.equal(2) | ||
expect(await this.ketlCred.balanceOf(this.owner.address)).to.equal(1) | ||
}) | ||
it('should not burn KetlCred when upvote is removed', async function () { | ||
await this.obssStorage.connect(this.user).addFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionType: 1, | ||
}) | ||
const reactionBefore = await this.feeds.usersToReactions( | ||
0, | ||
0, | ||
0, | ||
this.user.address | ||
) | ||
expect(reactionBefore.reactionType).to.equal(1) | ||
await this.obssStorage.connect(this.user).removeFeedReaction({ | ||
feedId: 0, | ||
postId: 0, | ||
commentId: 0, | ||
reactionId: reactionBefore.reactionId, | ||
}) | ||
const reactionAfter = await this.feeds.usersToReactions( | ||
0, | ||
0, | ||
0, | ||
this.user.address | ||
) | ||
expect(reactionAfter.sender).to.equal(zeroAddress) | ||
expect(await this.ketlCred.balanceOf(this.owner.address)).to.equal(1) | ||
}) | ||
}) | ||
}) |
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
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 |
---|---|---|
@@ -1,7 +1,33 @@ | ||
import type { OBSSStorage__factory } from '../typechain' | ||
import { MockContract } from 'ethereum-waffle' | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' | ||
import type { | ||
Feeds, | ||
Feeds__factory, | ||
KetlCred, | ||
KetlCred__factory, | ||
OBSSStorage, | ||
OBSSStorage__factory, | ||
Profiles, | ||
Profiles__factory, | ||
} from '../typechain' | ||
|
||
declare module 'mocha' { | ||
export interface Context { | ||
factory: OBSSStorage__factory | ||
// Factories for contracts | ||
profilesFactory: Profiles__factory | ||
feedsFactory: Feeds__factory | ||
ketlCredFactory: KetlCred__factory | ||
obssStorageFactory: OBSSStorage__factory | ||
// Contract instances | ||
profiles: Profiles | ||
feeds: Feeds | ||
ketlCred: KetlCred | ||
obssStorage: OBSSStorage | ||
// Mock contracts | ||
fakeKetlAttestationContract: MockContract | ||
// Signers | ||
accounts: SignerWithAddress[] | ||
owner: SignerWithAddress | ||
user: SignerWithAddress | ||
} | ||
} |
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,39 @@ | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' | ||
import { allowMapInput } from '.' | ||
import { deployMockContract } from 'ethereum-waffle' | ||
|
||
export async function getFakeCommitmentProof() { | ||
return { | ||
a: [1, 2], | ||
b: [ | ||
[1, 2], | ||
[3, 4], | ||
], | ||
c: [1, 2], | ||
input: await allowMapInput(), | ||
} | ||
} | ||
|
||
export async function getFakeKetlAttestationContract( | ||
signer: SignerWithAddress | ||
) { | ||
return await deployMockContract(signer, [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider importing contract ABI from |
||
{ | ||
inputs: [ | ||
{ internalType: 'address', name: 'account', type: 'address' }, | ||
{ internalType: 'uint256', name: 'id', type: 'uint256' }, | ||
], | ||
name: 'balanceOf', | ||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
inputs: [], | ||
name: 'currentTokenId', | ||
outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
]) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
as
is still needed becauseupgrades.deployProxy
still doesn't support generics: OpenZeppelin/openzeppelin-upgrades#535