68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
const { expect } = require('chai');
|
|
const io = require('socket.io-client');
|
|
|
|
const SERVER_URL = 'http://localhost:3000';
|
|
|
|
describe('Token Economy', function () {
|
|
this.timeout(5000);
|
|
let socket;
|
|
const walletAddress = 'TokenTestWallet_' + Date.now();
|
|
const username = 'TokenUser_' + Date.now();
|
|
|
|
before((done) => {
|
|
// Ensure server is running (assuming it's started externally or we rely on it)
|
|
// For this test, we assume the server is running on port 3000 as per package.json start script
|
|
// If not, we might need to start it here, but usually integration tests assume environment
|
|
|
|
socket = io(SERVER_URL);
|
|
socket.on('connect', done);
|
|
});
|
|
|
|
after((done) => {
|
|
if (socket.connected) {
|
|
socket.disconnect();
|
|
}
|
|
done();
|
|
});
|
|
|
|
it('should initialize user with 100 PLEXUS', (done) => {
|
|
socket.emit('join', { walletAddress, username });
|
|
|
|
socket.once('balanceUpdated', (data) => {
|
|
expect(data.balance).to.equal(100);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should deduct 1 PLEXUS when sending a message', (done) => {
|
|
// Wait for join to complete if not already
|
|
// We can just emit sendMessage, but we need to be sure we are joined?
|
|
// The previous test joined, so we should be good.
|
|
|
|
const channelId = 'nebula';
|
|
const content = 'Hello World';
|
|
const txId = 'TX_TEST_' + Date.now();
|
|
|
|
// Listen for balance update
|
|
socket.once('balanceUpdated', (data) => {
|
|
expect(data.balance).to.equal(99);
|
|
done();
|
|
});
|
|
|
|
socket.emit('sendMessage', { channelId, walletAddress, content, txId });
|
|
});
|
|
|
|
it('should deduct 30 PLEXUS when changing username', (done) => {
|
|
const newUsername = 'RichUser_' + Date.now();
|
|
const txId = 'TX_NAME_' + Date.now();
|
|
|
|
socket.once('balanceUpdated', (data) => {
|
|
// 99 - 30 = 69
|
|
expect(data.balance).to.equal(69);
|
|
done();
|
|
});
|
|
|
|
socket.emit('updateUsername', { walletAddress, newUsername, txId });
|
|
});
|
|
});
|