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

Integrate nonce test #146

Merged
merged 17 commits into from
Dec 7, 2023
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"format": "prettier --parser typescript --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx}'",
"type-check": "tsc --noEmit",
"check-nonce": "npm run build && node dist/helpers/scripts/checkNonceTracking.js",
"mocha": "mocha --config=tests/.mocharc.json --node-env=test --exit",
"mocha": "mocha --config=tests/.mocharc.json --node-env=test --timeout 10000 --exit",
"test": "npm run lint && npm run test:unit:cover && npm run test:integration:cover",
"test:unit": "npm run mocha -- 'tests/unit/**/*.test.ts'",
"test:unit:storage": "npm run mocha -- 'tests/unit/storage.test.ts'",
Expand Down
10 changes: 10 additions & 0 deletions tests/data/nonceSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { TypesenseCollectionCreateSchema } from '../../src/@types'

export const nonceSchema: TypesenseCollectionCreateSchema = {
name: 'nonce',
enable_nested_fields: true,
fields: [
{ name: 'id', type: 'string' },
{ name: 'nonce', type: 'int64', sort: true } // store nonce as string
]
}
8 changes: 4 additions & 4 deletions tests/integration/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Database', () => {

before(async () => {
const dbConfig = {
url: 'http://localhost:8108/?apiKey=xyz'
url: 'http://172.15.0.6:8108/?apiKey=xyz'
}
database = await new Database(dbConfig)
})
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('DdoDatabase CRUD', () => {

before(async () => {
const dbConfig = {
url: 'http://localhost:8108/?apiKey=xyz'
url: 'http://172.15.0.6:8108/?apiKey=xyz'
}
database = await new Database(dbConfig)
})
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('NonceDatabase CRUD', () => {

before(async () => {
const dbConfig = {
url: 'http://localhost:8108/?apiKey=xyz'
url: 'http://172.15.0.6:8108/?apiKey=xyz'
}
database = await new Database(dbConfig)
})
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('IndexerDatabase CRUD', () => {

before(async () => {
const dbConfig = {
url: 'http://localhost:8108/?apiKey=xyz'
url: 'http://172.15.0.6:8108/?apiKey=xyz'
}
database = await new Database(dbConfig)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/indexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Indexer stores a new published DDO', () => {

before(async () => {
const dbConfig = {
url: 'http://localhost:8108/?apiKey=xyz'
url: 'http://172.15.0.6:8108/?apiKey=xyz'
}
database = await new Database(dbConfig)
indexer = new OceanIndexer(database, mockSupportedNetworks)
Expand Down
68 changes: 68 additions & 0 deletions tests/integration/nonce.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect } from 'chai'
import { ethers } from 'ethers'
import { nonceSchema } from '../data/nonceSchema.js'
import {
Typesense,
convertTypesenseConfig
} from '../../src/components/database/typesense'

describe('handle nonce', () => {
let typesense: Typesense

before(() => {
const url = 'http://172.15.0.6:8108/?apiKey=xyz'
typesense = new Typesense(convertTypesenseConfig(url))
})

it('instance Typesense', async () => {
expect(typesense).to.be.instanceOf(Typesense)
})

it('create nonce collection', async () => {
let result
try {
result = await typesense.collections(nonceSchema.name).retrieve()
} catch (error) {
result = await typesense.collections().create(nonceSchema)
}
expect(result.enable_nested_fields).to.equal(true)
expect(result.fields).to.not.be.an('undefined')
expect(result.name).to.be.equal(nonceSchema.name)
expect(result.num_documents).to.equal(0)
})

it('should validate signature', async () => {
try {
await typesense
.collections(nonceSchema.name)
.documents()
.retrieve('0x4cc9DBfc4bEeA8c986c61DAABB350C2eC55e29d1')
console.log('document in checkDocumentExists: ', document)
// if not, create it now
} catch (ex) {
await typesense.collections(nonceSchema.name).documents().create({
id: '0x4cc9DBfc4bEeA8c986c61DAABB350C2eC55e29d1',
nonce: 1
})
}
const wallet = new ethers.Wallet(
'0xbee525d70c715bee6ca15ea5113e544d13cc1bb2817e07113d0af7755ddb6391'
)
// message to sign
const nonce = '1'
const expectedAddress = await wallet.getAddress()
// '0x8F292046bb73595A978F4e7A131b4EBd03A15e8a'
// sign message/nonce
const signature = await wallet.signMessage(nonce)
const actualAddress = ethers.verifyMessage(nonce, signature)
expect(actualAddress).to.be.equal(expectedAddress)
})

it('should get nonce (1)', async () => {
const document = await typesense
.collections('nonce')
.documents()
.retrieve('0x4cc9DBfc4bEeA8c986c61DAABB350C2eC55e29d1')
expect(document.nonce).to.be.equal(1)
})
})
8 changes: 4 additions & 4 deletions tests/integration/typesense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Typesense', () => {
let typesense: Typesense

before(() => {
const url = 'http://localhost:8108/?apiKey=xyz'
const url = 'http://172.15.0.6:8108/?apiKey=xyz'
typesense = new Typesense(convertTypesenseConfig(url))
})

Expand All @@ -29,7 +29,7 @@ describe('Typesense collections', () => {
let typesense: Typesense

before(() => {
const url = 'http://localhost:8108/?apiKey=xyz'
const url = 'http://172.15.0.6:8108/?apiKey=xyz'
typesense = new Typesense(convertTypesenseConfig(url))
})

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Typesense documents', () => {
let typesense: Typesense

before(() => {
const url = 'http://localhost:8108/?apiKey=xyz'
const url = 'http://172.15.0.6:8108/?apiKey=xyz'
typesense = new Typesense(convertTypesenseConfig(url))
})

Expand Down Expand Up @@ -143,7 +143,7 @@ describe('Typesense documents', () => {
let typesense: Typesense

before(() => {
const url = 'http://localhost:8108/?apiKey=xyz'
const url = 'http://172.15.0.6:8108/?apiKey=xyz'
typesense = new Typesense(convertTypesenseConfig(url))
})

Expand Down
97 changes: 0 additions & 97 deletions tests/unit/nonce.spec.ts

This file was deleted.

Loading