Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.
Open
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
18 changes: 17 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14-alpine
FROM node:14-alpine as develop

WORKDIR /app

Expand All @@ -10,5 +10,21 @@ RUN yarn build

EXPOSE 3000

CMD ["yarn", "start"]

######

FROM node:14-alpine as production

WORKDIR /app

COPY package.json yarn.lock LICENSE /app/
RUN yarn install --production --frozen-lockfile

COPY environment /app/environment
COPY --from=develop /app/dist /app/dist

EXPOSE 3000

# $NODE_ENV must be exported with -e
CMD ["yarn", "run", "start:provided-env"]
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ services:
- 9944:9944
command: --dev --ws-port 9944 --ws-external
services:
build: .
build:
context: .
target: develop
image: local/prototype-services
env_file:
- environment/docker-compose.env
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@godaddy/terminus": "^4.6.0",
"@kiltprotocol/chain-helpers": "^0.22.0",
"@kiltprotocol/config": "^0.22.0",
"@kiltprotocol/core": "^0.22.0",
Expand All @@ -34,9 +33,6 @@
"dotenv": "^8.2.0",
"mongoose": "^5.11.15",
"reflect-metadata": "^0.1.12",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"typescript": "^4.1.3",
"typescript-optional": "^2.0.1"
},
"devDependencies": {
Expand All @@ -48,15 +44,18 @@
"jest": "26.4.2",
"mongodb-memory-server": "^6.6.3",
"nodemon": "^1.18.3",
"prettier": "^1.14.2",
"prettier": "^2.0.2",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"supertest": "^3.1.0",
"ts-jest": "^26.3.0",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.17.0",
"tslint-plugin-prettier": "^2.0.1"
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^4.1.3"
},
"jest": {
"moduleFileExtensions": [
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ExecutionContext,
Inject,
} from '@nestjs/common'
import { Observable } from 'rxjs'
import type { Observable } from 'rxjs'
import { ConfigService } from '../config/config.service'

@Injectable()
Expand Down
3 changes: 2 additions & 1 deletion src/blockchain/universal-blockchain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { BlockchainService } from './interfaces/blockchain.interfaces'

@Injectable()
export class UniversalBlockchainService
implements BlockchainService, OnApplicationBootstrap {
implements BlockchainService, OnApplicationBootstrap
{
private static instance: Promise<Blockchain>
constructor(
@Inject('ConfigService') private readonly configService: ConfigService
Expand Down
4 changes: 3 additions & 1 deletion src/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { ConfigService } from './config.service'
providers: [
{
provide: ConfigService,
useValue: new ConfigService(`./environment/${process.env.NODE_ENV}.env`),
useValue: new ConfigService(
`./environment/${process.env.NODE_ENV || ''}.env`
),
},
],
exports: [ConfigService],
Expand Down
4 changes: 3 additions & 1 deletion src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export class ConfigService {
private readonly envConfig: { [key: string]: string }

constructor(filePath: string) {
this.envConfig = dotenv.parse(fs.readFileSync(filePath))
this.envConfig = fs.existsSync(filePath)
? dotenv.parse(fs.readFileSync(filePath))
: {}
}

public get(key: string): string {
Expand Down
38 changes: 17 additions & 21 deletions src/contacts/contacts.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,20 @@ describe('Contact Module', () => {
let contactsController: ContactsController
let contactsService: ContactsService

const mockedVerifyDidDocumentSignature = require('@kiltprotocol/core/lib/did/Did')
.verifyDidDocumentSignature
const mockedVerifyDidDocumentSignature =
require('@kiltprotocol/core/lib/did/Did').verifyDidDocumentSignature
const fakeContactService: ContactsService = {
add: jest.fn(
async (): Promise<void> => {
return
}
),
add: jest.fn(async (): Promise<void> => {
return
}),
findByAddress: jest.fn(
async (): Promise<Optional<Contact>> =>
Optional.ofNullable<Contact>(null)
),
list: jest.fn(async (): Promise<Contact[]> => []),
removeAll: jest.fn(
async (): Promise<void> => {
return
}
),
removeAll: jest.fn(async (): Promise<void> => {
return
}),
}

beforeEach(async () => {
Expand Down Expand Up @@ -262,7 +258,7 @@ describe('Contact Module', () => {
return
},
})
public static save = jest.fn().mockImplementation(async object => object)
public static save = jest.fn().mockImplementation(async (object) => object)
public save = jest
.fn()
.mockImplementation(async () => ContactModel.save(this))
Expand Down Expand Up @@ -310,11 +306,11 @@ describe('Contact Module', () => {
.spyOn(contactsService['contactModel'], 'findOne')
.mockReturnValueOnce({
exec: async (): Promise<ContactDB> =>
(({
({
...deprecatedDIDFormat,
_id: 0,
toObject: () => deprecatedDIDFormat,
} as any) as ContactDB),
} as any as ContactDB),
})
const replaceOne = jest.spyOn(
contactsService['contactModel'],
Expand Down Expand Up @@ -355,10 +351,10 @@ describe('Contact Module', () => {
})
findOneSpy.mockReturnValue({
exec: async (): Promise<ContactDB> =>
(({
({
...testContact,
toObject: () => testContact,
} as any) as ContactDB),
} as any as ContactDB),
})
expect(await contactsService.findByAddress(address)).toEqual(
Optional.ofNullable<Contact>(testContact)
Expand All @@ -368,10 +364,10 @@ describe('Contact Module', () => {
})
findOneSpy.mockReturnValue({
exec: async (): Promise<ContactDB> =>
(({
({
...deprecatedDIDFormat,
toObject: () => deprecatedDIDFormat,
} as any) as ContactDB),
} as any as ContactDB),
})
expect(await contactsService.findByAddress(address)).toEqual(
Optional.ofNullable<Contact>(contactWithDid)
Expand All @@ -387,10 +383,10 @@ describe('Contact Module', () => {
.mockReturnValue({
exec: async (): Promise<ContactDB[]> => {
return [
({
{
...testContact,
toObject: () => testContact,
} as any) as ContactDB,
} as any as ContactDB,
]
},
})
Expand Down
13 changes: 6 additions & 7 deletions src/contacts/mongodb-contacts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ export class MongoDbMContactsService implements ContactsService {
) {}

public async add(contact: Contact): Promise<void> {
const registeredContact: Optional<
ContactDB & { signature?: string }
> = Optional.ofNullable<ContactDB & { signature?: string }>(
await this.contactModel
.findOne({ 'publicIdentity.address': contact.publicIdentity.address })
.exec()
)
const registeredContact: Optional<ContactDB & { signature?: string }> =
Optional.ofNullable<ContactDB & { signature?: string }>(
await this.contactModel
.findOne({ 'publicIdentity.address': contact.publicIdentity.address })
.exec()
)
if (registeredContact.isPresent()) {
const registered = registeredContact.get()
// If the contact was already registered we want to replace the document, as it could exist in outdated format! Signature is still valid.
Expand Down
4 changes: 1 addition & 3 deletions src/ctypes/ctypes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export class CTypesController {

if (!result) {
console.log(
`The CType with hash: ${
cTypeInput.cType.hash
} already exists in this DB!`
`The CType with hash: ${cTypeInput.cType.hash} already exists in this DB!`
)
throw new AlreadyRegisteredException()
}
Expand Down
12 changes: 5 additions & 7 deletions src/ctypes/ctypes.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,18 @@ describe('CType Module', () => {

const blockchainApi = require('@kiltprotocol/chain-helpers/lib/blockchainApiConnection/BlockchainApiConnection')

const mockedGetOwner = require('@kiltprotocol/core/lib/ctype/CType.chain')
.getOwner
const mockedGetOwner =
require('@kiltprotocol/core/lib/ctype/CType.chain').getOwner

const fakeCTypeService: CTypeService = {
findByHash: jest.fn(
async (): Promise<Optional<CType>> => Optional.ofNullable<CType>(null)
),
findAll: jest.fn(async (): Promise<CType[]> => []),
register: jest.fn(async (): Promise<boolean> => true),
removeAll: jest.fn(
async (): Promise<void> => {
return
}
),
removeAll: jest.fn(async (): Promise<void> => {
return
}),
}

beforeAll(
Expand Down
8 changes: 2 additions & 6 deletions src/faucet/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export {
FaucetDropFailedTransferException,
} from './faucet-drop-failed-transfer'
export { FaucetDropFailedTransferException } from './faucet-drop-failed-transfer'
export { FaucetDropThrottledException } from './faucet-drop-throttled.exception'
export {
FaucetDropInvalidAddressException,
} from './faucet-drop-invalid-address.exception'
export { FaucetDropInvalidAddressException } from './faucet-drop-invalid-address.exception'
40 changes: 17 additions & 23 deletions src/faucet/faucet.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ jest.useFakeTimers()

jest.mock('@kiltprotocol/core/lib/balance/Balance.chain', () => {
return {
makeTransfer: jest.fn(
async (): Promise<SubmittableExtrinsic> => {
return {} as SubmittableExtrinsic
}
),
makeTransfer: jest.fn(async (): Promise<SubmittableExtrinsic> => {
return {} as SubmittableExtrinsic
}),
}
})

jest.mock('@kiltprotocol/chain-helpers/lib/blockchain/Blockchain.utils', () => {
return {
__esModule: true,
signAndSubmitTx: jest.fn().mockImplementation(
async (): Promise<ISubmittableResult> => {
signAndSubmitTx: jest
.fn()
.mockImplementation(async (): Promise<ISubmittableResult> => {
return { isInBlock: true } as ISubmittableResult
}
),
}),
}
})

Expand Down Expand Up @@ -77,24 +75,20 @@ describe('Faucet Module', () => {
let faucetController: FaucetController
let faucetService: FaucetService

const mockedMakeTransfer = require('@kiltprotocol/core/lib/balance/Balance.chain')
.makeTransfer
const mockedMakeTransfer =
require('@kiltprotocol/core/lib/balance/Balance.chain').makeTransfer

const mockedsubmitSignedTx = require('@kiltprotocol/chain-helpers/lib/blockchain/Blockchain.utils')
.signAndSubmitTx
const mockedsubmitSignedTx =
require('@kiltprotocol/chain-helpers/lib/blockchain/Blockchain.utils').signAndSubmitTx

const fakeFaucetService: FaucetService = {
drop: jest.fn(async (): Promise<FaucetDrop> => testFaucetDrop),
updateOnTransactionFailure: jest.fn(
async (): Promise<void> => {
return
}
),
reset: jest.fn(
async (): Promise<void> => {
return
}
),
updateOnTransactionFailure: jest.fn(async (): Promise<void> => {
return
}),
reset: jest.fn(async (): Promise<void> => {
return
}),
}
beforeAll(async () => {
await cryptoWaitReady()
Expand Down
2 changes: 1 addition & 1 deletion src/health/bc.health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class KiltChainConnectionIndicator extends HealthIndicator {
} catch (e) {
reject(e)
}
}).catch(e =>
}).catch((e) =>
Promise.reject(
new HealthCheckError(
'Error with Kilt chain connection',
Expand Down
8 changes: 4 additions & 4 deletions src/messaging/messaging.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ForbiddenMessageAccessException } from './exceptions/message-forbidden.
import { MessageNotFoundException } from './exceptions/message-not-found.exception'

export const uuidv4 = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c === 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
Expand All @@ -37,9 +37,9 @@ export class MessagingController {
@Param('id') id,
@Headers('signature') signature
): Promise<void> {
const { receiverAddress } = (await this.messagingService.findById(
id
)).orElseThrow(() => {
const { receiverAddress } = (
await this.messagingService.findById(id)
).orElseThrow(() => {
throw new MessageNotFoundException()
})

Expand Down
Loading