Skip to content
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 unit tests #107

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Generate auto-generated files
run: yarn codegen
Comment on lines +30 to +33
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use npm here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to change this to npm before we merge?

- name: Run tests
run: npm test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# Test coverage tools
tests/.tools/

# Matchstick binaries
tests/.*
matchstick

# nyc test coverage
.nyc_output

Expand Down Expand Up @@ -60,4 +67,6 @@ typings/
# next.js build output
.next

# Graph CLI
src/types/
build/
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"scripts": {
"create": "graph create aelin/aelin-mega --node https://api.thegraph.com/deploy/",
"create-local": "graph create aelin/aelin-mega --node http://127.0.0.1:8020",
"codegen": "graph codegen --debug --output-dir src/types/",
"build": "graph build --debug",
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"test": "graph test",
"coverage": "graph test -- -c",
"auth-hosted": "graph auth --product hosted-service $AELIN_GRAPH_ACCESS_TOKEN",
"auth-hosted:alex": "graph auth --product hosted-service $ALEX_GRAPH_ACCESS_TOKEN",
"deploy-hosted:kovan": "graph deploy --product hosted-service aelin-xyz/aelin-kovan",
Expand Down Expand Up @@ -39,8 +41,8 @@
"prettier:fix": "prettier --write \"./**/*.{js,jsx,ts,tsx}\""
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.25.0",
"@graphprotocol/graph-ts": "0.25.0",
"@graphprotocol/graph-cli": "^0.40.0",
"@graphprotocol/graph-ts": "^0.29.3",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"eslint": "^8.10.0",
Expand All @@ -49,6 +51,7 @@
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.5",
"matchstick-as": "^0.5.1",
"prettier": "^2.5.1",
"typescript": "^4.7.4"
},
Expand All @@ -66,4 +69,4 @@
"prettier --write"
]
}
}
}
42 changes: 21 additions & 21 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type PoolCreated @entity {
symbol: String!

" the cap on the amount of purchase tokens in the pool. If 0 - that means uncapped "
purchaseTokenCap: BigInt!
purchaseTokenCap: BigInt

" the address of the purchase token "
purchaseToken: Bytes!
Expand All @@ -62,7 +62,7 @@ type PoolCreated @entity {
purchaseTokenSymbol: String!

" the duration of the pool assuming no deal is presented when purchasers can withdraw all of their locked funds "
duration: BigInt!
duration: BigInt

" the fee paid to the sponsor when a purchaser accepts a deal "
sponsorFee: BigInt!
Expand All @@ -83,7 +83,7 @@ type PoolCreated @entity {
timestamp: BigInt!

" if there is an allow list on the pool "
hasAllowList: Boolean!
hasAllowList: Boolean

" the current status of the pool "
poolStatus: PoolStatus!
Expand All @@ -92,7 +92,7 @@ type PoolCreated @entity {
contributions: BigInt!

" the total supply of pool tokens "
totalSupply: BigInt!
totalSupply: BigInt

" the address of the current proposed deal on the pool "
dealAddress: Bytes
Expand All @@ -114,25 +114,25 @@ type PoolCreated @entity {

vestingEnds: BigInt

holder: Bytes!
holder: Bytes

"poolName-sponsorAddress-purchaseTokenSymbol"
filter: String!

totalUsersInvested: Int!

totalAddressesInvested: [String!]!
totalAddressesInvested: [String!]

hasNftList: Boolean!

nftCollectionRules: [NftCollectionRule!]!
nftCollectionRules: [NftCollectionRule!]

" details of the created upfront deal "
upfrontDeal: UpfrontDeal

totalVouchers: Int!

vouchers: [String!]!
vouchers: [String!]
}

type TotalPoolsCreated @entity {
Expand Down Expand Up @@ -675,43 +675,43 @@ type UpfrontDeal @entity {
underlyingDealTokenDecimals: Int!

" the underlying deal token totalSupply "
underlyingDealTokenTotalSupply: BigInt!
underlyingDealTokenTotalSupply: BigInt

" the total amount of purchse tokens for the deal "
purchaseTokenTotalForDeal: BigInt!
purchaseTokenTotalForDeal: BigInt

" the total amount of underlying deal tokens available for the deal "
underlyingDealTokenTotal: BigInt!
underlyingDealTokenTotal: BigInt

" the vesting period which is linear for all deals in v1 "
vestingPeriod: BigInt!
vestingPeriod: BigInt

" the address of the holder of the underlying deal tokens who is receiving the underlying purchaser tokens "
holder: Bytes!

maxDealTotalSupply: BigInt!
maxDealTotalSupply: BigInt

purchaseTokenPerDealToken: BigInt!
purchaseTokenPerDealToken: BigInt

purchaseRaiseMinimum: BigInt!
purchaseRaiseMinimum: BigInt

vestingCliffPeriod: BigInt!
vestingCliffPeriod: BigInt

allowDeallocation: Boolean!
allowDeallocation: Boolean

dealStart: BigInt

totalAmountUnredeemed: BigInt!
totalAmountUnredeemed: BigInt

holderClaim: Boolean

sponsorClaim: Boolean

totalRedeemed: BigInt!
totalRedeemed: BigInt

totalUsersAccepted: Int!
totalUsersAccepted: Int

remainingDealTokens: BigInt!
remainingDealTokens: BigInt

merkleRoot: Bytes

Expand Down
3 changes: 3 additions & 0 deletions src/aelin-upfront-deal-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function handleCreateUpfrontDeal(event: CreateUpFrontDealEvent): void {
poolCreatedEntity.totalAmountEarnedBySponsor = ZERO
poolCreatedEntity.hasNftList = false
poolCreatedEntity.totalVouchers = 0
poolCreatedEntity.dealsCreated = 0
poolCreatedEntity.totalUsersInvested = 0

let userEntity = getOrCreateUser(event.params.sponsor.toHex())
if (userEntity != null) {
Expand Down Expand Up @@ -92,6 +94,7 @@ export function handleCreateUpfrontDeal(event: CreateUpFrontDealEvent): void {
// use templates to create a new pool to track events
AelinUpfrontDeal.create(event.params.dealAddress)
}

export function handleCreateUpfrontDealConfig(event: CreateUpFrontDealConfigEvent): void {
const upFrontDealEntity = getUpfrontDeal(event.params.dealAddress.toHex())
const poolCreatedEntity = getPoolCreated(event.params.dealAddress.toHex())
Expand Down
18 changes: 18 additions & 0 deletions src/services/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,12 @@ export function getOrCreateHistory(address: string): History | null {
if (historyEntity == null) {
historyEntity = new History(address)
historyEntity.user = address
historyEntity.vests = []
historyEntity.deposits = []
historyEntity.withdraws = []
historyEntity.dealsAccepted = []
historyEntity.dealsSponsored = []
historyEntity.dealsFunded = []
historyEntity.save()
}

Expand All @@ -1262,6 +1268,18 @@ export function getOrCreateUser(address: string): User | null {
let userEntity = User.load(address)
if (userEntity == null) {
userEntity = new User(address)
userEntity.poolsSponsored = []
userEntity.poolsVouched = []
userEntity.poolsVouchedAmt = 0
userEntity.poolsInvested = []
userEntity.poolsInvestedAmt = 0
userEntity.poolsAsHolder = []
userEntity.poolsAsHolderAmt = 0
userEntity.dealsAccepted = []
userEntity.dealsAcceptedAmt = 0
userEntity.upfrontDealsAccepted = []
userEntity.upfrontDealsAcceptedAmt = 0
userEntity.allocationsStat = []
}

return userEntity
Expand Down
2 changes: 1 addition & 1 deletion src/services/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ClaimedUnderlyingDealToken as ClaimedUnderlyingDealTokenEvent,
WithdrawUnderlyingDealToken as WithdrawUnderlyingDealTokenEvent,
} from '../types/templates/AelinDeal/AelinDeal'
import { CreatePool as CreatePoolEvent } from '../types/AelinPoolFactory/AelinPoolFactory'
import { CreatePool as CreatePoolEvent } from '../types/AelinPoolFactory_v4/AelinPoolFactory'
import { CreateUpFrontDeal as CreateUpFrontDealEvent } from '../types/AelinUpfrontDealFactory_v1/AelinUpfrontDealFactory'
import {
AcceptDeal as AcceptUpfrontDealEvent,
Expand Down
Loading