Skip to content

Commit abd5fec

Browse files
authored
Merge branch 'develop' into initial-glazed
2 parents 8a0877e + 0540dc6 commit abd5fec

File tree

17 files changed

+71
-77
lines changed

17 files changed

+71
-77
lines changed

clients/iscmove/isc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/iotaledger/wasp/v2/packages/cryptolib"
1818
)
1919

20-
func TestIscCodec(t *testing.T) {
20+
func TestISCCodec(t *testing.T) {
2121
type ExampleObj struct {
2222
A int
2323
}
@@ -51,7 +51,7 @@ func TestIscCodec(t *testing.T) {
5151
anchorRef.Object = &iscmovetest.TestAnchor
5252
anchorRef.ObjectID = &anchorRef.Object.ID
5353
anchorRef.Digest = iotatest.TestDigest
54-
bcs.TestCodecAndHash(t, anchorRef, "2ed70074c011")
54+
bcs.TestCodecAndHash(t, anchorRef, "2750607f6325")
5555

5656
bcs.TestCodecAndHash(t, iscmove.AssetsBagWithBalances{
5757
AssetsBag: iscmovetest.TestAssetsBag,

clients/iscmove/iscmoveclient/feed_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/samber/lo"
78
"github.com/stretchr/testify/require"
89

910
"github.com/iotaledger/wasp/v2/clients/iota-go/iotaclient"
1011
"github.com/iotaledger/wasp/v2/clients/iota-go/iotaconn"
1112
"github.com/iotaledger/wasp/v2/clients/iota-go/iotago"
13+
"github.com/iotaledger/wasp/v2/clients/iota-go/iotajsonrpc"
1214
testcommon "github.com/iotaledger/wasp/v2/clients/iota-go/test_common"
1315
"github.com/iotaledger/wasp/v2/clients/iscmove"
1416
"github.com/iotaledger/wasp/v2/clients/iscmove/iscmoveclient"
@@ -106,9 +108,11 @@ func TestRequestsFeed(t *testing.T) {
106108
SentAssets: []iscmoveclient.SentAssets{},
107109
StateMetadata: []byte{1, 2, 3},
108110
TopUpAmount: 100,
109-
GasPayment: getCoinsRes.Data[0].Ref(),
110-
GasPrice: iotaclient.DefaultGasPrice,
111-
GasBudget: iotaclient.DefaultGasBudget,
111+
GasPayment: lo.MaxBy(getCoinsRes.Data, func(a, b *iotajsonrpc.Coin) bool {
112+
return a.Balance.Int.Cmp(b.Balance.Int) >= 0
113+
}).Ref(),
114+
GasPrice: iotaclient.DefaultGasPrice,
115+
GasBudget: iotaclient.DefaultGasBudget,
112116
},
113117
)
114118
require.NoError(t, err)

packages/solo/ledgerl1l2.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,20 @@ func (ch *Chain) Withdraw(assets *isc.Assets, user *cryptolib.KeyPair) error {
183183

184184
// SendFromL1ToL2Account sends ftokens from L1 address to the target account on L2
185185
// Sender pays the gas fee
186-
func (ch *Chain) SendFromL1ToL2Account(totalBaseTokens coin.Value, toSend isc.CoinBalances, target isc.AgentID, user *cryptolib.KeyPair) error {
186+
func (ch *Chain) SendFromL1ToL2Account(toSend isc.CoinBalances, extraDeposit coin.Value, target isc.AgentID, user *cryptolib.KeyPair) error {
187187
require.False(ch.Env.T, toSend.IsEmpty())
188-
sumAssets := toSend.Clone().AddBaseTokens(totalBaseTokens)
189188
_, err := ch.PostRequestSync(
190189
NewCallParams(accounts.FuncTransferAllowanceTo.Message(target)).
191-
AddFungibleTokens(sumAssets).
190+
AddFungibleTokens(toSend.Clone().AddBaseTokens(extraDeposit)).
192191
AddAllowance(toSend.ToAssets()).
193192
WithGasBudget(math.MaxUint64),
194193
user,
195194
)
196195
return err
197196
}
198197

199-
func (ch *Chain) SendFromL1ToL2AccountBaseTokens(totalBaseTokens, baseTokensSend coin.Value, target isc.AgentID, user *cryptolib.KeyPair) error {
200-
return ch.SendFromL1ToL2Account(totalBaseTokens, isc.NewCoinBalances().AddBaseTokens(baseTokensSend), target, user)
198+
func (ch *Chain) SendFromL1ToL2AccountBaseTokens(toSend, extraDeposit coin.Value, target isc.AgentID, user *cryptolib.KeyPair) error {
199+
return ch.SendFromL1ToL2Account(isc.NewCoinBalances().AddBaseTokens(toSend), extraDeposit, target, user)
201200
}
202201

203202
// SendFromL2ToL2Account moves ftokens on L2 from user's account to the target

packages/solo/solo.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/iotaledger/wasp/v2/packages/vm/core/governance"
4646
"github.com/iotaledger/wasp/v2/packages/vm/core/migrations"
4747
"github.com/iotaledger/wasp/v2/packages/vm/core/migrations/allmigrations"
48+
"github.com/iotaledger/wasp/v2/packages/vm/gas"
4849
"github.com/iotaledger/wasp/v2/packages/vm/processors"
4950
_ "github.com/iotaledger/wasp/v2/packages/vm/sandbox"
5051
)
@@ -233,8 +234,9 @@ func (env *Solo) GetChainByName(name string) *Chain {
233234
panic("chain not found")
234235
}
235236

236-
const (
237-
DefaultChainAdminBaseTokens = 50 * isc.Million
237+
var (
238+
BaseTokensForL2Gas = gas.FeeFromGasWithGasPerToken(gas.LimitsDefault.MaxGasPerRequest, gas.DefaultGasPerToken)
239+
DefaultChainAdminBaseTokens = 2 * BaseTokensForL2Gas
238240
)
239241

240242
// NewChain deploys a new default chain instance.

packages/vm/core/evm/evmtest/evm_test.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,6 @@ func TestNotEnoughISCGas(t *testing.T) {
239239
_, err := storage.store(43)
240240
require.NoError(t, err)
241241

242-
// only the owner can call the setEVMGasRatio endpoint
243-
// set the ISC gas ratio VERY HIGH
244-
newGasRatio := util.Ratio32{A: gas.DefaultEVMGasRatio.A * 500, B: gas.DefaultEVMGasRatio.B}
245-
err = env.setEVMGasRatio(newGasRatio, iscCallOptions{wallet: env.Chain.ChainAdmin})
246-
require.NoError(t, err)
247-
require.Equal(t, newGasRatio, env.getEVMGasRatio())
248-
249242
senderAddress := crypto.PubkeyToAddress(storage.defaultSender.PublicKey)
250243
nonce := env.getNonce(senderAddress)
251244

@@ -281,7 +274,8 @@ func TestLoop(t *testing.T) {
281274
gasRatio := env.getEVMGasRatio()
282275

283276
for _, gasLimit := range []uint64{200000, 400000} {
284-
baseTokensSent := coin.Value(gas.EVMGasToISC(gasLimit, &gasRatio))
277+
iscGasUnits := gas.EVMGasToISC(gasLimit, &gasRatio)
278+
baseTokensSent := gas.FeeFromGasWithGasPerToken(iscGasUnits, gas.DefaultGasPerToken)
285279
ethKey2, ethAddr2 := env.Chain.NewEthereumAccountWithL2Funds(baseTokensSent)
286280
require.EqualValues(t,
287281
env.Chain.L2BaseTokens(isc.NewEthereumAddressAgentID(ethAddr2)),
@@ -307,7 +301,8 @@ func TestLoopWithGasLeft(t *testing.T) {
307301
gasRatio := env.getEVMGasRatio()
308302
var usedGas []uint64
309303
for _, gasLimit := range []uint64{50000, 200000} {
310-
baseTokensSent := coin.Value(gas.EVMGasToISC(gasLimit, &gasRatio))
304+
iscGasUnits := gas.EVMGasToISC(gasLimit, &gasRatio)
305+
baseTokensSent := gas.FeeFromGasWithGasPerToken(iscGasUnits, gas.DefaultGasPerToken)
311306
ethKey2, _ := env.Chain.NewEthereumAccountWithL2Funds(baseTokensSent)
312307
res, err := iscTest.CallFn([]ethCallOptions{{
313308
sender: ethKey2,
@@ -354,7 +349,8 @@ func TestLoopWithGasLeftEstimateGas(t *testing.T) {
354349
t.Log(estimatedGas)
355350

356351
gasRatio := env.getEVMGasRatio()
357-
baseTokensSent := coin.Value(gas.EVMGasToISC(estimatedGas, &gasRatio))
352+
iscGasUnits := gas.EVMGasToISC(estimatedGas, &gasRatio)
353+
baseTokensSent := gas.FeeFromGasWithGasPerToken(iscGasUnits, gas.DefaultGasPerToken)
358354
ethKey2, _ := env.Chain.NewEthereumAccountWithL2Funds(baseTokensSent)
359355
res, err := iscTest.CallFn([]ethCallOptions{{
360356
sender: ethKey2,
@@ -692,8 +688,8 @@ func TestCannotDepleteAccount(t *testing.T) {
692688
require.Zero(t, env.solo.L1BaseTokens(receiver))
693689
senderInitialBalance := env.Chain.L2BaseTokens(isc.NewEthereumAddressAgentID(ethAddress))
694690

695-
// we eill attempt to transfer so much that we are left with no funds for gas
696-
transfer := senderInitialBalance - 300
691+
// we will attempt to transfer so much that we are left with no funds for gas
692+
transfer := senderInitialBalance - gas.FeeFromGasWithGasPerToken(30_000, gas.DefaultGasPerToken)
697693

698694
// allow ISCTest to take the tokens
699695
_, err := env.ISCMagicSandbox(ethKey).CallFn(
@@ -1335,11 +1331,10 @@ func TestSelfDestruct(t *testing.T) {
13351331

13361332
// send some tokens to the ISCTest contract
13371333
{
1338-
const baseTokensDepositFee = 500
13391334
k, _ := env.solo.NewKeyPairWithFunds(env.solo.NewSeedFromTestNameAndTimestamp(t.Name()))
1340-
err := env.Chain.SendFromL1ToL2AccountBaseTokens(baseTokensDepositFee, 1*isc.Million, iscTestAgentID, k)
1335+
err := env.Chain.SendFromL1ToL2AccountBaseTokens(solo.BaseTokensForL2Gas, solo.BaseTokensForL2Gas, iscTestAgentID, k)
13411336
require.NoError(t, err)
1342-
require.EqualValues(t, 1*isc.Million, env.Chain.L2BaseTokens(iscTestAgentID))
1337+
require.EqualValues(t, solo.BaseTokensForL2Gas, env.Chain.L2BaseTokens(iscTestAgentID))
13431338
}
13441339

13451340
_, beneficiary := solo.EthereumAccountByIndex(1)
@@ -1353,7 +1348,7 @@ func TestSelfDestruct(t *testing.T) {
13531348
// except when called in the same transaction as creation
13541349
require.NotEmpty(t, env.getCode(iscTest.address))
13551350
require.Zero(t, env.Chain.L2BaseTokens(iscTestAgentID))
1356-
require.EqualValues(t, 1*isc.Million, env.Chain.L2BaseTokens(isc.NewEthereumAddressAgentID(beneficiary)))
1351+
require.EqualValues(t, solo.BaseTokensForL2Gas, env.Chain.L2BaseTokens(isc.NewEthereumAddressAgentID(beneficiary)))
13571352

13581353
testdbhash.VerifyContractStateHash(env.solo, evm.Contract, "", t.Name())
13591354
}

packages/vm/core/testcore/accounts_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"github.com/iotaledger/wasp/v2/packages/vm/gas"
2222
)
2323

24-
const BaseTokensDepositFee = 100
25-
2624
func TestAccounts_Deposit(t *testing.T) {
2725
env := solo.New(t, &solo.InitOptions{})
2826
sender, _ := env.NewKeyPairWithFunds(env.NewSeedFromTestNameAndTimestamp(t.Name()))
@@ -84,15 +82,15 @@ func TestAccounts_WithdrawEverything(t *testing.T) {
8482
ch := env.NewChain()
8583

8684
// deposit some base tokens to L2
87-
baseTokensToDepositToL2 := coin.Value(100_000)
85+
baseTokensToDepositToL2 := solo.BaseTokensForL2Gas
8886
err := ch.DepositBaseTokensToL2(baseTokensToDepositToL2, sender)
8987
require.NoError(t, err)
9088

9189
l2balance := ch.L2BaseTokens(senderAgentID)
9290

9391
// construct the request to estimate an withdrawal (leave a few tokens to pay for gas)
9492
req := solo.NewCallParams(accounts.FuncWithdraw.Message()).
95-
AddAllowance(isc.NewAssets(l2balance - 1000)).
93+
AddAllowance(isc.NewAssets(l2balance - solo.BaseTokensForL2Gas/10)).
9694
WithMaxAffordableGasBudget()
9795

9896
_, estimate, err := ch.EstimateGasOffLedger(req, sender)
@@ -161,7 +159,7 @@ func initDepositTest(t *testing.T, initCommonAccountBaseTokens ...coin.Value) *a
161159
// initWithdrawTest deploys TestCoin, mints 1M tokens and deposits 100 to user's account
162160
func initWithdrawTest(t *testing.T) *accountsDepositTest {
163161
v := initDepositTest(t)
164-
v.ch.MustDepositBaseTokensToL2(2*isc.Million, v.user)
162+
v.ch.MustDepositBaseTokensToL2(solo.BaseTokensForL2Gas, v.user)
165163
coinPackageID, treasuryCap := v.ch.Env.L1DeployCoinPackage(v.user)
166164
v.coinType = coin.MustTypeFromString(fmt.Sprintf(
167165
"%s::%s::%s",
@@ -182,7 +180,7 @@ func initWithdrawTest(t *testing.T) *accountsDepositTest {
182180
// prepare request parameters to withdraw
183181
// do not run the request yet
184182
v.req = solo.NewCallParams(accounts.FuncWithdraw.Message()).
185-
AddBaseTokens(12000).
183+
AddBaseTokens(solo.BaseTokensForL2Gas / 10).
186184
WithGasBudget(100_000)
187185
v.printBalances("BEGIN")
188186
return v
@@ -247,7 +245,7 @@ func TestAccounts_TransferAndCheckBaseTokens(t *testing.T) {
247245

248246
// deposit some base tokens into the common account
249247
someUserWallet, _ := v.env.NewKeyPairWithFunds()
250-
err := v.ch.SendFromL1ToL2Account(11*isc.Million, isc.NewAssets(10*isc.Million).Coins, accounts.CommonAccount(), someUserWallet)
248+
err := v.ch.SendFromL1ToL2Account(isc.NewAssets(10*isc.Million).Coins, solo.BaseTokensForL2Gas, accounts.CommonAccount(), someUserWallet)
251249
require.NoError(t, err)
252250
commonAccBaseTokens := initialCommonAccountBaseTokens + 10*isc.Million
253251
require.EqualValues(t, commonAccBaseTokens, v.ch.L2CommonAccountAssets().BaseTokens())
@@ -258,8 +256,8 @@ func TestAccounts_TransferAndCheckBaseTokens(t *testing.T) {
258256
func TestAccounts_TransferPartialAssets(t *testing.T) {
259257
// setup a chain with some base tokens and native tokens for user1
260258
v := initWithdrawTest(t)
261-
v.ch.MustDepositBaseTokensToL2(10*isc.Million, v.ch.ChainAdmin)
262-
v.ch.MustDepositBaseTokensToL2(10*isc.Million, v.user)
259+
v.ch.MustDepositBaseTokensToL2(solo.BaseTokensForL2Gas, v.ch.ChainAdmin)
260+
v.ch.MustDepositBaseTokensToL2(solo.BaseTokensForL2Gas, v.user)
263261

264262
v.ch.AssertL2Coins(v.userAgentID, v.coinType, coin.Value(100))
265263
v.ch.AssertL2TotalCoins(v.coinType, coin.Value(100))
@@ -270,12 +268,12 @@ func TestAccounts_TransferPartialAssets(t *testing.T) {
270268

271269
// deposit 1 base token to "create account" for user2 // TODO maybe remove if account creation is not needed
272270
v.ch.AssertL2BaseTokens(user2AgentID, 0)
273-
const baseTokensToSend = 3 * isc.Million
274-
err := v.ch.SendFromL1ToL2AccountBaseTokens(BaseTokensDepositFee, baseTokensToSend, user2AgentID, user2)
271+
const baseTokensToSend = 3e6
272+
err := v.ch.SendFromL1ToL2AccountBaseTokens(baseTokensToSend, solo.BaseTokensForL2Gas, user2AgentID, user2)
275273
rec := v.ch.LastReceipt()
276274
require.NoError(t, err)
277275
v.env.T.Logf("gas fee charged: %d", rec.GasFeeCharged)
278-
expectedUser2 := BaseTokensDepositFee + baseTokensToSend - rec.GasFeeCharged
276+
expectedUser2 := solo.BaseTokensForL2Gas + baseTokensToSend - rec.GasFeeCharged
279277
v.ch.AssertL2BaseTokens(user2AgentID, expectedUser2)
280278
// -----------------------------
281279
err = v.ch.SendFromL2ToL2Account(

packages/vm/core/testcore/governance_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func TestGovernanceL1Metadata(t *testing.T) {
331331
ch := env.NewChain()
332332

333333
// deposit some extra tokens to the common account to accommodate for the SD change
334-
ch.SendFromL1ToL2AccountBaseTokens(10*isc.Million, 9*isc.Million, accounts.CommonAccount(), nil)
334+
ch.SendFromL1ToL2AccountBaseTokens(solo.BaseTokensForL2Gas, solo.BaseTokensForL2Gas, accounts.CommonAccount(), nil)
335335

336336
// set max valid size custom metadata
337337
publicURLMetadata := "https://iota.org"
@@ -549,7 +549,7 @@ func TestGovernanceGasPayout(t *testing.T) {
549549
ownerBal1 := ch.L2Assets(ch.AdminAgentID())
550550
commonBal1 := ch.L2CommonAccountAssets()
551551
user1Bal1 := ch.L2Assets(user1AgentID)
552-
transferAmt := coin.Value(2000)
552+
transferAmt := solo.BaseTokensForL2Gas
553553
_, _, vmRes, _, err := ch.PostRequestSyncTx(
554554
solo.NewCallParams(accounts.FuncDeposit.Message()).
555555
AddBaseTokens(transferAmt),

packages/vm/core/testcore/sbtests/call_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ func TestGetSet(t *testing.T) {
1515
_, chain := setupChain(t)
1616
setupTestSandboxSC(t, chain, nil)
1717

18-
req := solo.NewCallParams(sbtestsc.FuncSetInt.Message("ppp", 314), ScName).
19-
WithGasBudget(100_000)
18+
req := solo.NewCallParams(sbtestsc.FuncSetInt.Message("ppp", 314), ScName)
2019
_, err := chain.PostRequestSync(req.AddBaseTokens(1), nil)
2120
require.NoError(t, err)
2221

packages/vm/core/testcore/sbtests/check_ctx_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/iotaledger/wasp/v2/packages/isc"
99
"github.com/iotaledger/wasp/v2/packages/solo"
1010
"github.com/iotaledger/wasp/v2/packages/vm/core/testcore/sbtests/sbtestsc"
11-
"github.com/iotaledger/wasp/v2/packages/vm/gas"
1211
)
1312

1413
func TestMainCallsFromFullEP(t *testing.T) {
@@ -22,8 +21,7 @@ func TestMainCallsFromFullEP(t *testing.T) {
2221
chain.AdminAgentID(),
2322
userAgentID,
2423
isc.NewContractAgentID(HScName),
25-
), ScName).
26-
WithGasBudget(10 * gas.LimitsDefault.MinGasPerRequest)
24+
), ScName)
2725
_, err := chain.PostRequestSync(req, user)
2826
require.NoError(t, err)
2927
}

packages/vm/core/testcore/sbtests/send_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,15 @@ func TestPingBaseTokens1(t *testing.T) {
149149
commonBefore := ch.L2CommonAccountAssets()
150150
t.Logf("----- BEFORE -----\nUser funds left: %s\nCommon account: %s", userFundsBefore, commonBefore)
151151

152-
const expectedBack = 1 * isc.Million
152+
expectedBack := solo.BaseTokensForL2Gas
153153
ch.Env.AssertL1BaseTokens(userAddr, iotaclient.FundsFromFaucetAmount)
154154

155155
req := solo.NewCallParamsEx(ScName, sbtestsc.FuncPingAllowanceBack.Name).
156-
AddBaseTokens(expectedBack + 500). // add extra base tokens besides allowance in order to estimate the gas fees
157-
AddAllowanceBaseTokens(expectedBack).
158-
WithGasBudget(100_000)
156+
AddBaseTokens(expectedBack * 2). // add extra base tokens besides allowance in order to estimate the gas fees
157+
AddAllowanceBaseTokens(expectedBack)
159158

160159
_, estimate, err := ch.EstimateGasOnLedger(req, user)
161160
require.NoError(t, err)
162-
163161
req.
164162
WithFungibleTokens(isc.NewAssets(expectedBack + estimate.GasFeeCharged).Coins).
165163
WithGasBudget(estimate.GasBurned)
@@ -223,7 +221,7 @@ func TestNFTOffledgerWithdraw(t *testing.T) {
223221
wallet, _ := ch.Env.NewKeyPairWithFunds(ch.Env.NewSeedFromTestNameAndTimestamp(t.Name()))
224222

225223
obj := ch.Env.L1MintObject(wallet)
226-
err := ch.DepositAssetsToL2(isc.NewAssets(100_000).AddObject(obj), wallet)
224+
err := ch.DepositAssetsToL2(isc.NewAssets(solo.BaseTokensForL2Gas).AddObject(obj), wallet)
227225
require.NoError(t, err)
228226

229227
wdReq := solo.NewCallParams(accounts.FuncWithdraw.Message()).

0 commit comments

Comments
 (0)