Skip to content
Merged
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
3 changes: 1 addition & 2 deletions backend/src/models/subSchedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const SubSchedule = sequelize.define('SubSchedule', {
allowNull: false,
},
cliff_duration: {
type: DataTypes.INTEGER,
allowNull: true,

},
cliff_date: {
type: DataTypes.DATE,
Expand Down
12 changes: 0 additions & 12 deletions backend/src/services/vestingService.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
class VestingService {

async exampleFunction() {
try {
return {
success: true,
message: "Vesting service is working"
};
} catch (error) {
throw error;
}
}

}

Expand Down
43 changes: 43 additions & 0 deletions backend/test-projection-mock.js
Original file line number Diff line number Diff line change
@@ -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();
61 changes: 61 additions & 0 deletions backend/test-projection.js
Original file line number Diff line number Diff line change
@@ -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();