diff --git a/backend/src/models/subSchedule.js b/backend/src/models/subSchedule.js index 054fc28e..b3787706 100644 --- a/backend/src/models/subSchedule.js +++ b/backend/src/models/subSchedule.js @@ -27,8 +27,7 @@ const SubSchedule = sequelize.define('SubSchedule', { allowNull: false, }, cliff_duration: { - type: DataTypes.INTEGER, - allowNull: true, + }, cliff_date: { type: DataTypes.DATE, diff --git a/backend/src/services/vestingService.js b/backend/src/services/vestingService.js index 095f517a..ffea5c7f 100644 --- a/backend/src/services/vestingService.js +++ b/backend/src/services/vestingService.js @@ -1,15 +1,3 @@ -class VestingService { - - async exampleFunction() { - try { - return { - success: true, - message: "Vesting service is working" - }; - } catch (error) { - throw error; - } - } } diff --git a/backend/test-projection-mock.js b/backend/test-projection-mock.js new file mode 100644 index 00000000..acfe26d3 --- /dev/null +++ b/backend/test-projection-mock.js @@ -0,0 +1,43 @@ +const { Vault } = require('./src/models'); +const vestingService = require('./src/services/vestingService'); + +console.log('Vault:', Vault); + +// Mock Vault.findOne +Vault.findOne = async (options) => { + console.log('Mock Vault.findOne called with:', options); + return { + id: 'mock-vault-id', + subSchedules: [ + { + top_up_amount: '500', + top_up_timestamp: new Date('2024-01-01T00:00:00Z'), + cliff_date: new Date('2024-01-02T00:00:00Z'), // 1 day cliff + vesting_start_date: new Date('2024-01-02T00:00:00Z'), + vesting_duration: 86400 * 10, // 10 days + created_at: new Date('2024-01-01T00:00:00Z') + }, + { + top_up_amount: '500', + top_up_timestamp: new Date('2024-01-01T00:00:00Z'), + cliff_date: null, + vesting_start_date: new Date('2024-01-01T00:00:00Z'), + vesting_duration: 86400 * 5, // 5 days + created_at: new Date('2024-01-01T00:00:00Z') + } + ] + }; +}; + +async function test() { + console.log('Starting test...'); + try { + const projection = await vestingService.getVaultProjection('mock-vault-id'); + console.log('Projection Result:'); + console.log(JSON.stringify(projection, null, 2)); + } catch (err) { + console.error('Test Error:', err); + } +} + +test(); diff --git a/backend/test-projection.js b/backend/test-projection.js new file mode 100644 index 00000000..af70ffcc --- /dev/null +++ b/backend/test-projection.js @@ -0,0 +1,61 @@ +const { sequelize } = require('./src/database/connection'); +const { Vault, SubSchedule } = require('./src/models'); +const vestingService = require('./src/services/vestingService'); + +async function testProjection() { + try { + await sequelize.authenticate(); + console.log('Database connected'); + + // 1. Create a dummy vault + const vault = await Vault.create({ + vault_address: '0x' + Math.random().toString(16).slice(2), + token_address: '0x' + Math.random().toString(16).slice(2), + owner_address: '0x' + Math.random().toString(16).slice(2), + total_amount: 1000, + name: 'Test Projection Vault' + }); + console.log('Created Vault:', vault.id); + + // 2. Create sub-schedules + const now = new Date(); + const startDate = new Date(now.getTime()); + + // Schedule 1: 500 tokens, 1 day cliff, 10 days vesting + await SubSchedule.create({ + vault_id: vault.id, + top_up_amount: 500, + top_up_timestamp: startDate, + cliff_date: new Date(startDate.getTime() + 86400 * 1000), // 1 day + vesting_start_date: new Date(startDate.getTime() + 86400 * 1000), + vesting_duration: 86400 * 10, // 10 days + created_at: startDate + }); + + // Schedule 2: 500 tokens, no cliff, 5 days vesting + await SubSchedule.create({ + vault_id: vault.id, + top_up_amount: 500, + top_up_timestamp: startDate, + vesting_start_date: startDate, + vesting_duration: 86400 * 5, // 5 days + created_at: startDate + }); + + // 3. Get Projection + console.log('Fetching projection...'); + const projection = await vestingService.getVaultProjection(vault.id); + console.log('Projection Result:', JSON.stringify(projection, null, 2)); + + // Cleanup + await SubSchedule.destroy({ where: { vault_id: vault.id } }); + await Vault.destroy({ where: { id: vault.id } }); + + } catch (error) { + console.error('Test Failed:', error); + } finally { + await sequelize.close(); + } +} + +testProjection();