Skip to content

Commit

Permalink
Merge pull request #5338 from multiversx/update-vm-common-and-fix-log…
Browse files Browse the repository at this point in the history
…-upgrade-properties

Update vm-common and `upgradeProperties` log
  • Loading branch information
miiu96 authored Jun 15, 2023
2 parents fc8bae7 + 7e156c0 commit 5ccfe17
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/multiversx/mx-chain-logger-go v1.0.11
github.com/multiversx/mx-chain-p2p-go v1.0.14
github.com/multiversx/mx-chain-storage-go v1.0.7
github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613095316-dc368cff52d4
github.com/multiversx/mx-chain-vm-common-go v1.3.42
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.81
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2
github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg=
github.com/multiversx/mx-chain-vm-common-go v1.3.40/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE=
github.com/multiversx/mx-chain-vm-common-go v1.3.41/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE=
github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613095316-dc368cff52d4 h1:f3DI+ql0lC0mpXVhzLJj2/HCvQ0D4Fb2KErWSgpCxiM=
github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613095316-dc368cff52d4/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE=
github.com/multiversx/mx-chain-vm-common-go v1.3.42 h1:avhgUwi6f+wpHqaBk76j6islLzUlSRBXwisKoZnUXpk=
github.com/multiversx/mx-chain-vm-common-go v1.3.42/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 h1:c+S0xhfOMtwWEJHMqoPf8plF3sLnz3euPj4Rd/wN2UQ=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54/go.mod h1:iuM50SqgelbKYNEm9s4BZcWczIgyCJIGFKajGUCDVm0=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 h1:hmo/QQ/qY+WgsMQeBODIX+tEnM/XIf7izNs9+WbKg4Y=
Expand Down
30 changes: 23 additions & 7 deletions vm/systemSmartContracts/esdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,27 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args
mintBurnable = false
}

topics := make([][]byte, 0)
nonce := big.NewInt(0)
topics = append(topics, tokenIdentifier, nonce.Bytes())
logEntry := &vmcommon.LogEntry{
Identifier: []byte(upgradeProperties),
Address: callerAddr,
}

if len(args) == 0 {
topics = append(topics, []byte(upgradable), boolToSlice(token.Upgradable), []byte(canAddSpecialRoles), boolToSlice(token.CanAddSpecialRoles))
logEntry.Topics = topics
e.eei.AddLogEntry(logEntry)

return nil
}
if len(args)%2 != 0 {
return vm.ErrInvalidNumOfArguments
}

isUpgradablePropertyInArgs := false
isCanAddSpecialRolePropertyInArgs := false
for i := 0; i < len(args); i += 2 {
optionalArg := string(args[i])
val, err := checkAndGetSetting(string(args[i+1]))
Expand All @@ -726,10 +740,12 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args
token.CanWipe = val
case upgradable:
token.Upgradable = val
isUpgradablePropertyInArgs = true
case canChangeOwner:
token.CanChangeOwner = val
case canAddSpecialRoles:
token.CanAddSpecialRoles = val
isCanAddSpecialRolePropertyInArgs = true
case canTransferNFTCreateRole:
token.CanTransferNFTCreateRole = val
case canCreateMultiShard:
Expand All @@ -748,15 +764,15 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args
}
}

topics := make([][]byte, 0)
nonce := big.NewInt(0)
topics = append(topics, tokenIdentifier, nonce.Bytes())
topics = append(topics, args...)
logEntry := &vmcommon.LogEntry{
Identifier: []byte(upgradeProperties),
Address: callerAddr,
Topics: topics,
if !isUpgradablePropertyInArgs {
topics = append(topics, []byte(upgradable), boolToSlice(token.Upgradable))
}
if !isCanAddSpecialRolePropertyInArgs {
topics = append(topics, []byte(canAddSpecialRoles), boolToSlice(token.CanAddSpecialRoles))
}

logEntry.Topics = topics
e.eei.AddLogEntry(logEntry)

return nil
Expand Down
18 changes: 18 additions & 0 deletions vm/systemSmartContracts/esdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ func TestEsdt_ExecuteIssueWithMultiNFTCreate(t *testing.T) {
returnCode = e.Execute(vmInput)
assert.Equal(t, vmcommon.Ok, returnCode)

upgradePropertiesLog := eei.logs[0]
expectedTopics := [][]byte{[]byte("TICKER-75fd57"), big.NewInt(0).Bytes(), []byte(canCreateMultiShard), boolToSlice(true), []byte(upgradable), boolToSlice(true), []byte(canAddSpecialRoles), boolToSlice(true)}
assert.Equal(t, &vmcommon.LogEntry{
Identifier: []byte(upgradeProperties),
Address: []byte("addr"),
Topics: expectedTopics,
}, upgradePropertiesLog)

lastOutput := eei.output[len(eei.output)-1]
token, _ := e.getExistingToken(lastOutput)
assert.True(t, token.CanCreateMultiShard)
Expand Down Expand Up @@ -252,11 +260,21 @@ func TestEsdt_ExecuteIssue(t *testing.T) {

vmInput.Arguments = append(vmInput.Arguments, big.NewInt(100).Bytes())
vmInput.Arguments = append(vmInput.Arguments, big.NewInt(10).Bytes())
vmInput.Arguments = append(vmInput.Arguments, []byte(upgradable), boolToSlice(false))
vmInput.Arguments = append(vmInput.Arguments, []byte(canAddSpecialRoles), boolToSlice(false))
vmInput.CallValue, _ = big.NewInt(0).SetString(args.ESDTSCConfig.BaseIssuingCost, 10)
vmInput.GasProvided = args.GasCost.MetaChainSystemSCsCost.ESDTIssue
output = e.Execute(vmInput)
assert.Equal(t, vmcommon.Ok, output)

upgradePropertiesLog := eei.logs[0]
expectedTopics := [][]byte{[]byte("TICKER-75fd57"), big.NewInt(0).Bytes(), []byte(upgradable), boolToSlice(false), []byte(canAddSpecialRoles), boolToSlice(false)}
assert.Equal(t, &vmcommon.LogEntry{
Identifier: []byte(upgradeProperties),
Address: []byte("addr"),
Topics: expectedTopics,
}, upgradePropertiesLog)

vmInput.Arguments[0] = []byte("01234567891&*@")
output = e.Execute(vmInput)
assert.Equal(t, vmcommon.UserError, output)
Expand Down

0 comments on commit 5ccfe17

Please sign in to comment.