Skip to content

Commit

Permalink
fix: use unix seconds intead of milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemmsilva committed Sep 2, 2024
1 parent 444be3a commit 8cc2347
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions packages/vm/core/evm/evmtest/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,47 @@ func TestSendPayableValueTX(t *testing.T) {
require.EqualValues(t, valueInBaseTokens, env.solo.L1BaseTokens(receiver))
}

func TestSendTimelock(t *testing.T) {
env := InitEVM(t, false)

ethKey, senderEthAddress := env.Chain.NewEthereumAccountWithL2Funds()
_, receiver := env.solo.NewKeyPair()

require.Zero(t, env.solo.L1BaseTokens(receiver))
senderInitialBalance := env.Chain.L2BaseTokens(isc.NewEthereumAddressAgentID(env.Chain.ChainID, senderEthAddress))

value := util.BaseTokensDecimalsToEthereumDecimals(1*isc.Million, parameters.L1().BaseToken.Decimals)

res, err := env.ISCMagicSandbox(ethKey).CallFn(
[]ethCallOptions{{sender: ethKey, value: value, gasLimit: 100_000}},
"send", iscmagic.WrapL1Address(receiver),
iscmagic.WrapISCAssets(isc.NewEmptyAssets()),
false, // auto adjust SD
iscmagic.ISCSendMetadata{},
iscmagic.ISCSendOptions{
Timelock: 1,
Expiration: iscmagic.ISCExpiration{
Time: 0,
ReturnAddress: iscmagic.L1Address{},
},
},
)
require.NoError(t, err)

decimals := parameters.L1().BaseToken.Decimals
valueInBaseTokens, bigRemainder := util.EthereumDecimalsToBaseTokenDecimals(
value,
decimals,
)
require.Zero(t, bigRemainder.BitLen())

// L2 balance of sender is: initial - value sent in tx - gas fee
require.EqualValues(t, senderInitialBalance-valueInBaseTokens-res.ISCReceipt.GasFeeCharged, env.Chain.L2BaseTokens(isc.NewEthereumAddressAgentID(env.Chain.ChainID, senderEthAddress)))
}

func TestFooBar(t *testing.T) {
}

func TestSendBaseTokens(t *testing.T) {
env := InitEVM(t, true)

Expand Down
4 changes: 2 additions & 2 deletions packages/vm/core/evm/iscmagic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (i *ISCExpiration) Unwrap() *isc.Expiration {

ret := isc.Expiration{
ReturnAddress: address,
Time: time.UnixMilli(i.Time),
Time: time.Unix(i.Time, 0),
}

return &ret
Expand All @@ -367,7 +367,7 @@ func (i *ISCSendOptions) Unwrap() isc.SendOptions {
var timeLock time.Time

if i.Timelock > 0 {
timeLock = time.UnixMilli(i.Timelock)
timeLock = time.Unix(i.Timelock, 0)
}

ret := isc.SendOptions{
Expand Down

0 comments on commit 8cc2347

Please sign in to comment.