From dda2b11f605a09ffc514b3d099715a03f93a0fed Mon Sep 17 00:00:00 2001 From: Philip Mataras Date: Fri, 18 Oct 2024 10:56:28 -0400 Subject: [PATCH] Trying to fix test... --- src/main.lua | 10 ++++++++-- tests/gar.test.mjs | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main.lua b/src/main.lua index f7225837..13176cd1 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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) @@ -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 diff --git a/tests/gar.test.mjs b/tests/gar.test.mjs index 5c7efb25..4ed8d6f1 100644 --- a/tests/gar.test.mjs +++ b/tests/gar.test.mjs @@ -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]: { @@ -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( @@ -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( @@ -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]: { @@ -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; }); + + }); });