Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions src/faucet/faucet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
Req,
Body,
BadRequestException,
Delete,
UseGuards,
} from '@nestjs/common'
import { Request } from 'express'
import BN from 'bn.js'
Expand All @@ -18,6 +20,7 @@ import {
FaucetDropFailedTransferException,
FaucetDropInvalidAddressException,
} from './exceptions'
import { AuthGuard } from '../auth/auth.guard'

const KILT_FEMTO_COIN = '1000000000000000'
const DEFAULT_TOKEN_AMOUNT = 500
Expand Down Expand Up @@ -54,6 +57,13 @@ export class FaucetController {
}
}

@UseGuards(AuthGuard)
@Delete()
public async reset() {
console.log('Purging faucet drop registry')
this.faucetService.reset()
}

private async transferTokens(address: string): Promise<boolean> {
try {
console.log(`Transfer tokens from faucet to ${address}`)
Expand Down
28 changes: 20 additions & 8 deletions src/faucet/faucet.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Request } from 'express'
import { BadRequestException } from '@nestjs/common'
import { MongoDbFaucetService } from './mongodb-faucet.service'
import { getModelToken } from '@nestjs/mongoose'
import { AuthGuard } from '../auth/auth.guard'

jest.mock('@kiltprotocol/sdk-js/build/balance/Balance.chain', () => {
return {
Expand Down Expand Up @@ -83,7 +84,10 @@ describe('Faucet Module', () => {
useValue: fakeFaucetService,
},
],
}).compile()
})
.overrideGuard(AuthGuard)
.useValue({ canActivate: () => true })
.compile()

faucetController = moduleRef.get(FaucetController)
faucetService = moduleRef.get('FaucetService')
Expand All @@ -95,9 +99,9 @@ describe('Faucet Module', () => {
const buildSpy = jest
.spyOn(Identity, 'buildFromSeed')
.mockResolvedValue(faucetIdentity)
expect(await faucetController.drop(claimerAddress, faucetRequest)).toEqual(
undefined
)
expect(
await faucetController.drop(claimerAddress, faucetRequest)
).toEqual(undefined)
expect(dropSpy).toHaveBeenCalledWith(
claimerAddress,
testFaucetDrop.requestip,
Expand Down Expand Up @@ -183,7 +187,9 @@ describe('Faucet Module', () => {
isFinalized: true,
} as SubmittableResult
})
expect(await faucetController['transferTokens'](claimerAddress)).toEqual(true)
expect(
await faucetController['transferTokens'](claimerAddress)
).toEqual(true)
expect(buildSpy).toHaveBeenCalledWith(
hexToU8a(process.env.FAUCET_ACCOUNT)
)
Expand All @@ -200,7 +206,9 @@ describe('Faucet Module', () => {
throw new Error('buildFromSeed failed')
})

expect(await faucetController['transferTokens'](claimerAddress)).toEqual(false)
expect(
await faucetController['transferTokens'](claimerAddress)
).toEqual(false)
expect(buildSpy).toHaveBeenCalledWith(
hexToU8a(process.env.FAUCET_ACCOUNT)
)
Expand All @@ -209,7 +217,9 @@ describe('Faucet Module', () => {
mockedMakeTransfer.mockImplementation(() => {
throw new Error('makeTransfer failed')
})
expect(await faucetController['transferTokens'](claimerAddress)).toEqual(false)
expect(
await faucetController['transferTokens'](claimerAddress)
).toEqual(false)
expect(buildSpy).toHaveBeenCalledWith(
hexToU8a(process.env.FAUCET_ACCOUNT)
)
Expand All @@ -223,7 +233,9 @@ describe('Faucet Module', () => {
isFinalized: false,
} as SubmittableResult
})
expect(await faucetController['transferTokens'](claimerAddress)).toEqual(false)
expect(
await faucetController['transferTokens'](claimerAddress)
).toEqual(false)
expect(buildSpy).toHaveBeenCalledWith(
hexToU8a(process.env.FAUCET_ACCOUNT)
)
Expand Down