-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1st round test finish for claim
- Loading branch information
Showing
7 changed files
with
161 additions
and
23 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function(options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
}; | ||
|
||
exports.up = function(db) { | ||
return db.addColumn('token', 'claim', { type: 'boolean', notNull: true, defaultValue: false }) | ||
}; | ||
|
||
exports.down = function(db) { | ||
return db.removeColumn('token', 'claim'); | ||
}; | ||
|
||
exports._meta = { | ||
"version": 1 | ||
}; |
27 changes: 27 additions & 0 deletions
27
database/migrations/20210401015411-AddColClaimBooleanTransferTable.js
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,27 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function(options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
}; | ||
|
||
exports.up = function(db) { | ||
return db.addColumn('transfer', 'claim', { type: 'boolean' }) | ||
}; | ||
|
||
exports.down = function(db) { | ||
return db.removeColumn('transfer', 'claim'); | ||
}; | ||
|
||
exports._meta = { | ||
"version": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
function getRandomArbitrary(min, max) { | ||
return Math.random() * (max - min) + min; | ||
} | ||
|
||
(async () => { | ||
|
||
const Knex = require('knex') | ||
const faker = require('faker'); | ||
const { v4: uuidv4 } = require('uuid'); | ||
|
||
|
||
const Config = require('./config/config'); | ||
const knex = Knex({ | ||
client: 'pg', | ||
connection: Config.connectionString[process.env.NODE_ENV] | ||
}) | ||
|
||
const Crypto = require('crypto'); | ||
const sha512 = function(password, salt){ | ||
var hash = Crypto.createHmac('sha512', salt); /** Hashing algorithm sha512 */ | ||
hash.update(password); | ||
var value = hash.digest('hex'); | ||
return value; | ||
}; | ||
|
||
const username = faker.internet.userName() | ||
const password = faker.internet.password() // not a secure password | ||
const apiKey = faker.internet.password() | ||
|
||
const salt = faker.internet.password() // not a secure salt | ||
const passwordHash = sha512(password, salt) | ||
|
||
const trx = await knex.transaction(); | ||
|
||
try { | ||
|
||
|
||
// create API key | ||
const apiKeyData = { | ||
key: apiKey, | ||
tree_token_api_access: true, | ||
name: username | ||
} | ||
const result0 = await trx('wallet.api_key').insert(apiKeyData).returning('*') | ||
console.log(result0) | ||
|
||
// create wallet and password, salt | ||
|
||
const result = await trx('wallet.wallet').insert({ | ||
name: username, | ||
password: passwordHash, | ||
salt: salt | ||
}).returning('*') | ||
const wallet = result[0] | ||
console.log(wallet) | ||
|
||
|
||
// create fake tokens | ||
for(i=0; i<5000; i++){ | ||
const tokenData = { | ||
capture_id: uuidv4(), | ||
wallet_id: wallet.id, | ||
} | ||
const result4 = await trx('wallet.token').insert(tokenData).returning('*') | ||
const token = result4[0] | ||
console.log(token.id) | ||
} | ||
|
||
await trx.commit(); | ||
|
||
knex.destroy() | ||
|
||
console.log('wallet ' + username); | ||
console.log('password ' + password); | ||
console.log('apiKey ' + apiKey); | ||
|
||
} catch (error) { | ||
|
||
console.log(error) | ||
await trx.rollback() | ||
knex.destroy() | ||
|
||
} | ||
|
||
|
||
})().catch(e => console.error(e.stack)); |
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
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