Skip to content

Commit

Permalink
Trying to fix test...
Browse files Browse the repository at this point in the history
  • Loading branch information
vilenarios committed Oct 18, 2024
1 parent 928541a commit dda2b11
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,13 @@ addEventingHandler(
local target = utils.formatAddress(msg.Tags.Target or msg.Tags.Address)
local quantity = tonumber(msg.Tags.Quantity)
-- Convert the string value of Instant to a boolean value
local instantWithdraw = msg.Tags.Instant == "true"
local instantWithdraw = false
if msg.Tags.Instant and msg.Tags.Instant == "true" then
instantWithdraw = true
else
instantWithdraw = false
end

msg.ioEvent:addField("TargetFormatted", target)

local shouldContinue2, gateway = eventingPcall(msg.ioEvent, function(error)
Expand All @@ -1217,7 +1223,7 @@ addEventingHandler(
msg.ioEvent:addField("PreviousStake", newStake + quantity)
msg.ioEvent:addField("NewStake", newStake)
msg.ioEvent:addField("GatewayTotalDelegatedStake", gateway.totalDelegatedStake)
msg.ioEvent:addField("InstantWithdrawal", insantWithdraw)
msg.ioEvent:addField("InstantWithdrawal", instantWithdraw)
delegateResult = gateway.delegates[from]
local newDelegateVaults = delegateResult.vaults
if newDelegateVaults ~= nil then
Expand Down
40 changes: 36 additions & 4 deletions tests/gar.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ describe('GatewayRegistry', async () => {
);

const gatewayData = JSON.parse(gateway.Messages[0].Data);
console.log ("1: Gateway Data Is: ", gatewayData)

assert.deepEqual(gatewayData.delegates, {
[newStubAddress]: {
Expand All @@ -843,6 +842,39 @@ describe('GatewayRegistry', async () => {
sharedMemory = cancelWithdrawalResult.Memory;
});

it('should not decrease delegate stake with invalid instant withdrawal tag', async () => {
const instantWithdrawalTimestamp = stubbedTimestamp + 1000 * 60 * 15; // 15 minutes after stubbedTimestamp
const decreaseStakeResult = await handle(
{
From: newStubAddress,
Owner: newStubAddress,
Timestamp: instantWithdrawalTimestamp,
Id: ''.padEnd(43, 'x'),
Tags: [
{ name: 'Action', value: 'Decrease-Delegate-Stake' },
{ name: 'Address', value: STUB_ADDRESS },
{ name: 'Quantity', value: '1000000000' }, // 1K IO
{ name: 'Instant', value: 'false' }, // FOR SOME REASON THIS WORKS IF YOU PUT 'false' :O
],
},
sharedMemory,
);

// get the updated gateway record
const gateway = await handle(
{
Tags: [
{ name: 'Action', value: 'Gateway' },
{ name: 'Address', value: STUB_ADDRESS },
],
Timestamp: instantWithdrawalTimestamp + 1,
},
decreaseStakeResult.Memory,
);
const gatewayData = JSON.parse(gateway.Messages[0].Data);
assert.deepEqual(gatewayData.totalDelegatedStake, 2_000_000_000);
});

it('should decrease delegate stake with instant withdrawal', async () => {
const instantWithdrawalTimestamp = stubbedTimestamp + 1000 * 60 * 15; // 15 minutes after stubbedTimestamp
const decreaseStakeResult = await handle(
Expand All @@ -860,8 +892,6 @@ describe('GatewayRegistry', async () => {
},
sharedMemory,
);

console.log ("2: decrease stake result: ", decreaseStakeResult.Messages[0].Data)

// get the updated gateway record
const gateway = await handle(
Expand All @@ -875,7 +905,6 @@ describe('GatewayRegistry', async () => {
decreaseStakeResult.Memory,
);
const gatewayData = JSON.parse(gateway.Messages[0].Data);
console.log ("3: gateway result: ", gatewayData)
// Assertions
assert.deepEqual(gatewayData.delegates, {
[newStubAddress]: {
Expand Down Expand Up @@ -948,9 +977,12 @@ describe('GatewayRegistry', async () => {
);

gatewayData = JSON.parse(gateway.Messages[0].Data);
console.log ("1: ", gatewayData)
assert.deepEqual(gatewayData.delegates, []);
assert.deepEqual(gatewayData.totalDelegatedStake, 0);
sharedMemory = instantDecreaseStakeResult.Memory;
});


});
});

0 comments on commit dda2b11

Please sign in to comment.