Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Assorted T3 fixes (#1057)
Browse files Browse the repository at this point in the history
* Make Sequelize usage more consistent with other origin packages
* vestGrant / vestGrants tests
* Login fixes
* Get rid of moment warning in client
* Use natural units when calling token.credit()
* Refactor token transfer + transfer tests
* Set network ID through NETWORK_ID
* Minimal server logging
* Increase test timeout to give CI a better chance of passing
* Lengthen timeout for another test
  • Loading branch information
cuongdo committed Dec 10, 2018
1 parent 04dbde7 commit 88587cb
Show file tree
Hide file tree
Showing 18 changed files with 611 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ matrix:
node_js: 10
install:
- npm install --ignore-scripts
- npm run bootstrap -- --scope origin-token-transfer-client --scope origin-token-transfer-server
- npm run bootstrap -- --scope origin-contracts --scope origin-faucet --scope origin-token-transfer-client --scope origin-token-transfer-server
script:
- npm run test --prefix origin-token-transfer/server
- npm run test --prefix origin-token-transfer/client
10 changes: 7 additions & 3 deletions origin-faucet/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ function createProviders(networkIds) {
}
// Private key takes precedence
if (privateKey) {
console.log(`Network=${networkId} URL=${providerUrl} Using private key`)
if (process.env.NODE_ENV !== 'test') {
console.log(`Network=${networkId} URL=${providerUrl} Using private key`)
}
providers[networkId] = new PrivateKeyProvider(privateKey, providerUrl)
} else {
const displayMnemonic = (networkId === LOCAL_NETWORK_ID) ? mnemonic : '[redacted]'
console.log(`Network=${networkId} Url=${providerUrl} Mnemonic=${displayMnemonic}`)
if (process.env.NODE_ENV !== 'test') {
const displayMnemonic = (networkId === LOCAL_NETWORK_ID) ? mnemonic : '[redacted]'
console.log(`Network=${networkId} Url=${providerUrl} Mnemonic=${displayMnemonic}`)
}
providers[networkId] = new HDWalletProvider(mnemonic, providerUrl)
}
}
Expand Down
13 changes: 10 additions & 3 deletions origin-js/test/resource_marketplace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,9 @@ describe('Marketplace Resource', function() {
.to.be.rejectedWith('cannot accept invalid offer 999-000-1-0')
})

it('should not deduct units available for withdrawn offers', async () => {
it('should not deduct units available for withdrawn offers', async function() {
this.timeout(35000)

// Create and accept offer for 1 unit.
await marketplace.makeOffer('999-000-1', offerData)
let offer1 = await marketplace.getOffer('999-000-1-0')
Expand Down Expand Up @@ -916,7 +918,12 @@ describe('Marketplace Resource', function() {
})

describe('makeOffer', () => {
it('should allow 3 offers to be accepted', async () => {
it('should allow 3 offers to be accepted', async function() {
// Without the discovery server, this test is slow. To allow CI to pass,
// we increase the timeout.
// TODO: optimize this test, if possible
this.timeout(35000)

// Create first offer, for which there is sufficient listing commission
// for an offer with full commission.
const offer1Data = Object.assign({}, multiUnitCommissionOffer,
Expand Down Expand Up @@ -956,7 +963,7 @@ describe('Marketplace Resource', function() {
expect(offers[1].id).to.equal('999-000-1-1')
expect(offers[2].id).to.equal('999-000-1-2')
})
}).timeout(30000)
})

describe('getOffers', () => {
it('should filter offers with insufficient per-unit commission', async () => {
Expand Down
10 changes: 7 additions & 3 deletions origin-token-transfer/client/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { connect } from 'react-redux'
import { setSessionEmail } from '../actions'

class Login extends Component {
handleError = (err) => {
handleError = err => {
Toaster.create({
message: `Google login error: {err}`,
message: `Google login error: ${err}`,
intent: Intent.DANGER
})
}
Expand Down Expand Up @@ -39,7 +39,11 @@ class Login extends Component {
render() {
return (
<div>
{this.props.sessionEmail && <Redirect to="/grants" /> }
{
this.props.sessionEmail
&& this.props.sessionEmail !== '(need to login)'
&& <Redirect to="/grants" />
}
<Dialog id="loginDialog" isOpen={true}>
<div className="bp3-dialog-header">
<span className="bp3-icon-large bp3-icon-arrow-right"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class TransferDialog extends Component {
amount: this.state.amount,
address: this.state.address
}
console.log(transferRequest)

const postBody = new Blob(
[ JSON.stringify(transferRequest) ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Grants', {
await queryInterface.createTable('Grant', {
id: {
autoIncrement: true,
primaryKey: true,
Expand All @@ -12,19 +12,19 @@ module.exports = {
type: Sequelize.TEXT,
allowNull: false
},
grantedAt: {
granted_at: {
type: Sequelize.DATE,
allowNull: false
},
amount: {
type: Sequelize.INTEGER,
allowNull: false
},
totalMonths: {
total_months: {
type: Sequelize.INTEGER,
allowNull: false
},
cliffMonths: {
cliff_months: {
type: Sequelize.INTEGER,
allowNull: false
},
Expand All @@ -37,18 +37,18 @@ module.exports = {
allowNull: false
},
// Auto-generated by Sequelize
createdAt: {
created_at: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
updated_at: {
allowNull: false,
type: Sequelize.DATE
}
})
return queryInterface.addIndex('Grants', { fields: ['email'] })
return queryInterface.addIndex('Grant', { fields: ['email'] })
},
down: (queryInterface) => {
return queryInterface.dropTable('Grants')
return queryInterface.dropTable('Grant')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Events', {
return queryInterface.createTable('Event', {
id: {
allowNull: false,
autoIncrement: true,
Expand All @@ -17,9 +17,9 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false
},
grantId: {
grant_id: {
type: Sequelize.INTEGER,
references: { model: 'Grants', key: 'id' }
references: { model: 'Grant', key: 'id' }
},
action: {
type: Sequelize.STRING,
Expand All @@ -28,17 +28,17 @@ module.exports = {
data: {
type: Sequelize.STRING
},
createdAt: {
created_at: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
updated_at: {
allowNull: false,
type: Sequelize.DATE
}
})
},
down: (queryInterface) => {
return queryInterface.dropTable('Events')
return queryInterface.dropTable('Event')
}
}
3 changes: 2 additions & 1 deletion origin-token-transfer/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"start": "per-env",
"start:development": "nodemon src/app.js",
"start:production": "node src/app.js",
"test": "mocha -r @babel/register -r @babel/polyfill -t 10000 --exit",
"test": "NODE_ENV=test mocha -r @babel/register -r @babel/polyfill -t 10000 --exit",
"vest": "node src/scripts/vest_grants.js"
},
"author": "",
Expand Down Expand Up @@ -55,6 +55,7 @@
"@babel/preset-env": "^7.2.0",
"@babel/register": "^7.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^3.0.0",
"chai-moment": "^0.1.0",
"mocha": "^5.2.0",
Expand Down
42 changes: 21 additions & 21 deletions origin-token-transfer/server/seeders/20181018104132-demo-grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@
// TODO: create seeder that reads in a CSV file
module.exports = {
up: (queryInterface) => {
return queryInterface.bulkInsert('Grants', [
return queryInterface.bulkInsert('Grant', [
{
email: 'cuong@originprotocol.com',
grantedAt: '2010-01-31 00:00:00',
granted_at: '2010-01-31 00:00:00',
amount: 120000,
totalMonths: 48,
cliffMonths: 12,
total_months: 48,
cliff_months: 12,
vested: 120000,
transferred: 100000,
createdAt: new Date(),
updatedAt: new Date()
created_at: new Date(),
updated_at: new Date()
},
{
email: 'cuong@originprotocol.com',
grantedAt: '2017-01-31 00:00:00',
granted_at: '2017-01-31 00:00:00',
amount: 480,
totalMonths: 48,
cliffMonths: 12,
total_months: 48,
cliff_months: 12,
vested: 0,
transferred: 0,
createdAt: new Date(),
updatedAt: new Date()
created_at: new Date(),
updated_at: new Date()
},
{
email: 'cuong@originprotocol.com',
grantedAt: '2017-08-01 00:00:00',
granted_at: '2017-08-01 00:00:00',
amount: 112,
totalMonths: 48,
cliffMonths: 12,
total_months: 48,
cliff_months: 12,
vested: 0,
transferred: 0,
createdAt: new Date(),
updatedAt: new Date()
created_at: new Date(),
updated_at: new Date()
},
{
email: 'cuong@originprotocol.com',
grantedAt: '2018-08-01 00:00:00',
granted_at: '2018-08-01 00:00:00',
amount: 120,
totalMonths: 48,
cliffMonths: 12,
total_months: 48,
cliff_months: 12,
vested: 0,
transferred: 0,
createdAt: new Date(),
updatedAt: new Date()
created_at: new Date(),
updated_at: new Date()
}
], {})
},
Expand Down
Loading

0 comments on commit 88587cb

Please sign in to comment.