Skip to content

Commit

Permalink
fix token type log
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed May 19, 2022
1 parent 0c156ea commit b98ec2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion vm/systemSmartContracts/esdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re
logEntry := &vmcommon.LogEntry{
Identifier: []byte(args.Function),
Address: args.CallerAddr,
Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], []byte(metaESDT)},
Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], tokenType},
}
e.eei.Finish(tokenIdentifier)
e.eei.AddLogEntry(logEntry)
Expand All @@ -553,6 +553,7 @@ func getAllRolesForTokenType(tokenType string) ([][]byte, error) {
}

func getTokenType(compressed []byte) (bool, []byte, error) {
// TODO: might extract the compressed constants to core, alongside metaESDT
switch string(compressed) {
case "NFT":
return false, []byte(core.NonFungibleESDT), nil
Expand Down
13 changes: 10 additions & 3 deletions vm/systemSmartContracts/esdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4592,9 +4592,16 @@ func TestEsdt_ExecuteRegisterAndSetSemiFungible(t *testing.T) {
assert.Equal(t, token.TokenType, []byte(core.SemiFungibleESDT))
}

func TestEsdt_ExecuteRegisterAndSetMetaESDT(t *testing.T) {
func TestEsdt_ExecuteRegisterAndSetMetaESDTShouldSetType(t *testing.T) {
t.Parallel()

registerAndSetAllRolesWithTypeCheck(t, []byte("NFT"), []byte(core.NonFungibleESDT))
registerAndSetAllRolesWithTypeCheck(t, []byte("SFT"), []byte(core.SemiFungibleESDT))
registerAndSetAllRolesWithTypeCheck(t, []byte("META"), []byte(metaESDT))
registerAndSetAllRolesWithTypeCheck(t, []byte("FNG"), []byte(core.FungibleESDT))
}

func registerAndSetAllRolesWithTypeCheck(t *testing.T, typeArgument []byte, expectedType []byte) {
args := createMockArgumentsForESDT()
eei, _ := NewVMContext(
&mock.BlockChainHookStub{},
Expand All @@ -4608,7 +4615,7 @@ func TestEsdt_ExecuteRegisterAndSetMetaESDT(t *testing.T) {
vmInput := getDefaultVmInputForFunc("registerAndSetAllRoles", nil)
vmInput.CallValue = big.NewInt(0).Set(e.baseIssuingCost)

vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("TICKER"), []byte("META"), big.NewInt(10).Bytes()}
vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("TICKER"), typeArgument, big.NewInt(10).Bytes()}
eei.gasRemaining = 9999
eei.returnMessage = ""
output := e.Execute(vmInput)
Expand All @@ -4617,5 +4624,5 @@ func TestEsdt_ExecuteRegisterAndSetMetaESDT(t *testing.T) {
assert.True(t, strings.Contains(string(eei.output[0]), "TICKER-"))

token, _ := e.getExistingToken(eei.output[0])
assert.Equal(t, token.TokenType, []byte(metaESDT))
assert.Equal(t, expectedType, token.TokenType)
}

0 comments on commit b98ec2e

Please sign in to comment.