Skip to content

Commit

Permalink
Merge pull request #4 from Dharitri-org/raj
Browse files Browse the repository at this point in the history
v0.0.3
  • Loading branch information
bhagyaraj1208117 committed Mar 26, 2024
2 parents f97cee2 + 6926f44 commit 401dcb1
Show file tree
Hide file tree
Showing 39 changed files with 1,167 additions and 544 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/Dharitri-org/drtg-vm-util
go 1.20

require (
github.com/Dharitri-org/drtg-bigint v0.0.0
github.com/Dharitri-org/drtg-vm-common v0.0.3
github.com/Dharitri-org/drtg-bigint v0.0.1
github.com/Dharitri-org/drtg-vm-common v0.0.4
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/Dharitri-org/drtg-bigint v0.0.0 h1:EcrkQcYxLg+RCQre5ezwQu79ylS5HUFb7+WN4dDajBE=
github.com/Dharitri-org/drtg-bigint v0.0.0/go.mod h1:ylHJu49RWsuap7jF/t+adMT7thADEIqoKa6wUaG+BWA=
github.com/Dharitri-org/drtg-vm-common v0.0.3 h1:MGIJ2N4GbQrSBBskUQ8uBTpL9oGNhzZlyFbzfQ8Fmmc=
github.com/Dharitri-org/drtg-vm-common v0.0.3/go.mod h1:tDiSMwcuHkyTfIk3w4rqi7NdB8PeuQrPknPd3fgdimg=
github.com/Dharitri-org/drtg-bigint v0.0.1 h1:Saq5SxL4o1VzGib+YeI3AzxSdlGK71Qk79/W8i+kHvc=
github.com/Dharitri-org/drtg-bigint v0.0.1/go.mod h1:ylHJu49RWsuap7jF/t+adMT7thADEIqoKa6wUaG+BWA=
github.com/Dharitri-org/drtg-vm-common v0.0.4 h1:fgW9WmHVS+HeOPNqsd10zvJGs0IH1FGpoyHz3QayypA=
github.com/Dharitri-org/drtg-vm-common v0.0.4/go.mod h1:tDiSMwcuHkyTfIk3w4rqi7NdB8PeuQrPknPd3fgdimg=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
8 changes: 5 additions & 3 deletions mock-hook-blockchain/worldCallbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package callbackblockchain

import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"math/big"

vmcommon "github.com/Dharitri-org/drtg-vm-common"
Expand All @@ -12,7 +14,7 @@ var _ vmcommon.BlockchainHook = (*BlockchainHookMock)(nil)

var zero = big.NewInt(0)

// NewAddress adapts between K model and elrond function
// NewAddress adapts between K model and dharitri function
func (b *BlockchainHookMock) NewAddress(creatorAddress []byte, creatorNonce uint64, _ []byte) ([]byte, error) {
// explicit new address mocks
for _, newAddressMock := range b.NewAddressMocks {
Expand Down Expand Up @@ -154,11 +156,11 @@ func (b *BlockchainHookMock) GetAllState(_ []byte) (map[string][]byte, error) {
return make(map[string][]byte), nil
}

// GetNonce should retrieve the nonce of an account
// GetUserAccount retrieves account info from map, or error if not found.
func (b *BlockchainHookMock) GetUserAccount(address []byte) (vmcommon.UserAccountHandler, error) {
account := b.AcctMap.GetAccount(address)
if account == nil {
return nil, errors.New("account not found")
return nil, fmt.Errorf("account not found: %s", hex.EncodeToString(address))
}

return account, nil
Expand Down
4 changes: 2 additions & 2 deletions mock-hook-blockchain/worldUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (b *BlockchainHookMock) UpdateAccounts(
if len(modAcct.Code) > 0 {
acct.Code = modAcct.Code
}
if len(modAcct.Data) > 0 {
acct.AsyncCallData = string(modAcct.Data)
if len(modAcct.OutputTransfers) > 0 && len(modAcct.OutputTransfers[0].Data) > 0 {
acct.AsyncCallData = string(modAcct.OutputTransfers[0].Data)
}

for _, stu := range modAcct.StorageUpdates {
Expand Down
4 changes: 2 additions & 2 deletions test-util/denali/controller/scenarioOne.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func (r *ScenarioRunner) RunSingleJSONScenario(contextPath string) error {
return err
}

r.Parser.FileResolver.SetContext(contextPath)
r.Parser.ValueInterpreter.FileResolver.SetContext(contextPath)
scenario, parseErr := r.Parser.ParseScenarioFile(byteValue)
if parseErr != nil {
return parseErr
}

return r.Executor.ExecuteScenario(scenario, r.Parser.FileResolver)
return r.Executor.ExecuteScenario(scenario, r.Parser.ValueInterpreter.FileResolver)
}

// tool to modify scenarios
Expand Down
9 changes: 4 additions & 5 deletions test-util/denali/controller/scenarioRunner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package denalicontroller

import (
fr "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/fileresolver"
mj "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/model"
mjparse "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/parse"
)
Expand All @@ -13,7 +14,7 @@ type ScenarioExecutor interface {
// ExecuteScenario executes the scenario and checks if it passed. Failure is signaled by returning an error.
// The FileResolver helps with resolving external steps.
// TODO: group into a "execution context" param.
ExecuteScenario(*mj.Scenario, mjparse.FileResolver) error
ExecuteScenario(*mj.Scenario, fr.FileResolver) error
}

// ScenarioRunner is a component that can run json scenarios, using a provided executor.
Expand All @@ -23,11 +24,9 @@ type ScenarioRunner struct {
}

// NewScenarioRunner creates new ScenarioRunner instance.
func NewScenarioRunner(executor ScenarioExecutor, fileResolver mjparse.FileResolver) *ScenarioRunner {
func NewScenarioRunner(executor ScenarioExecutor, fileResolver fr.FileResolver) *ScenarioRunner {
return &ScenarioRunner{
Executor: executor,
Parser: mjparse.Parser{
FileResolver: fileResolver,
},
Parser: mjparse.NewParser(fileResolver),
}
}
2 changes: 1 addition & 1 deletion test-util/denali/controller/testOne.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *TestRunner) RunSingleJSONTest(contextPath string) error {
return err
}

r.Parser.FileResolver.SetContext(contextPath)
r.Parser.ValueInterpreter.FileResolver.SetContext(contextPath)
top, parseErr := r.Parser.ParseTestFile(byteValue)
if parseErr != nil {
return parseErr
Expand Down
7 changes: 3 additions & 4 deletions test-util/denali/controller/testRunner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package denalicontroller

import (
fr "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/fileresolver"
mj "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/model"
mjparse "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/parse"
)
Expand All @@ -18,11 +19,9 @@ type TestRunner struct {
}

// NewTestRunner creates new TestRunner instance.
func NewTestRunner(executor TestExecutor, fileResolver mjparse.FileResolver) *TestRunner {
func NewTestRunner(executor TestExecutor, fileResolver fr.FileResolver) *TestRunner {
return &TestRunner{
Executor: executor,
Parser: mjparse.Parser{
FileResolver: fileResolver,
},
Parser: mjparse.NewParser(fileResolver),
}
}
8 changes: 5 additions & 3 deletions test-util/denali/controller/util.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package denalicontroller

import mjparse "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/parse"
import (
fr "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/fileresolver"
)

// NewDefaultFileResolver yields a new DefaultFileResolver instance.
// Reexported here to avoid having all external packages importing the parser.
// DefaultFileResolver is in parse for local tests only.
func NewDefaultFileResolver() *mjparse.DefaultFileResolver {
return mjparse.NewDefaultFileResolver()
func NewDefaultFileResolver() *fr.DefaultFileResolver {
return fr.NewDefaultFileResolver()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package denalijsonparse
package denalifileresolver

// FileResolver resolves values starting with "file:"
// FileResolver resolves Denali values starting with "file:"
type FileResolver interface {
// Clone creates new instance of the same type.
Clone() FileResolver

// SetContext sets directory where the test runs, to help resolve relative paths.
SetContext(contextPath string)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package denalijsonparse
package denalifileresolver

import (
"io/ioutil"
Expand Down Expand Up @@ -28,6 +28,14 @@ func (fr *DefaultFileResolver) ReplacePath(pathInTest, actualPath string) *Defau
return fr
}

// Clone creates new instance of the same type.
func (fr *DefaultFileResolver) Clone() FileResolver {
return &DefaultFileResolver{
contextPath: fr.contextPath,
contractPathReplacements: fr.contractPathReplacements,
}
}

// SetContext sets directory where the test runs, to help resolve relative paths.
func (fr *DefaultFileResolver) SetContext(contextPath string) {
fr.contextPath = contextPath
Expand Down
76 changes: 69 additions & 7 deletions test-util/denali/json/integrationTests/example.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@
"balance": "23,000",
"storage": {
"0x19efaebcc296cffac396adb4a60d54c05eff43926a6072498a618e943908efe1": "-5",
"``32_byte_key_____________________": "``string___interpreted___as__bytes"
"``32_byte_key_____________________": "``string___interpreted___as__bytes",
"``serialized_list_example": [
"``component1",
"``component2"
],
"``serialized_map_example": {
"``field1": "u32:5",
"``field2": [
"``field2elem1",
"u64:0",
"``field2elem3"
]
}
},
"code": "file:smart-contract.wasm"
}
Expand Down Expand Up @@ -60,23 +72,39 @@
"txId": "1",
"comment": "just an example",
"tx": {
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b000000000000000000000000",
"from": "address:an_address",
"to": "0x1000000000000000000000000000000000000000000000000000000000000000",
"value": "0x00",
"function": "someFunctionName",
"arguments": [
"0x1234123400000000000000000000000000000000000000000000000000000004",
"0x00",
"",
"``a message (as bytes)"
"``a message (as bytes)",
[
"``serialized_list_item_1",
"``serialized_list_item_2"
],
{
"``field1": "u32:5",
"``field2": "5"
}
],
"gasLimit": "0x100000",
"gasPrice": "0x01"
},
"expect": {
"out": [
"5",
"*"
"*",
[
"``serialized_list_item_1",
"``serialized_list_item_2"
],
{
"``field1": "u32:5",
"``field2": "5"
}
],
"status": "",
"logs": [
Expand Down Expand Up @@ -108,6 +136,25 @@
"gasPrice": "0"
}
},
{
"step": "scCall",
"txId": "1b",
"comment": "with minimal expected result",
"tx": {
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b000000000000000000000000",
"to": "0x1000000000000000000000000000000000000000000000000000000000000000",
"value": "0x00",
"function": "someFunctionName",
"arguments": [],
"gasLimit": "0x100000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "",
"logs": "*"
}
},
{
"step": "scDeploy",
"txId": "2",
Expand All @@ -130,7 +177,7 @@
"status": "",
"logs": [],
"gas": "*",
"refund": "0"
"refund": "5"
}
},
{
Expand Down Expand Up @@ -168,7 +215,15 @@
"balance": "23,000",
"storage": {
"0x19efaebcc296cffac396adb4a60d54c05eff43926a6072498a618e943908efe1": "-5",
"``32_byte_key_____________________": "``string___interpreted___as__bytes"
"``32_byte_key_____________________": "``string___interpreted___as__bytes",
"``serialized_map_example": {
"``field1": "u32:5",
"``field2": [
"``field2elem1",
"u64:0",
"``field2elem3"
]
}
},
"code": "file:smart-contract.wasm"
},
Expand All @@ -177,10 +232,17 @@
"balance": "*",
"storage": "*",
"code": "*",
"asyncCallData": "func@arg1@arg2"
"asyncCallData": "``func@arg1@arg2"
},
"``account_with_defaults___________": {
"storage": "*"
},
"+": ""
}
},
{
"step": "dumpState",
"comment": "print everything to consolecd"
}
]
}
2 changes: 1 addition & 1 deletion test-util/denali/json/integrationTests/example.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "file:smart-contract.wasm",
"asyncCallData": "someAsync@call@data"
"asyncCallData": "``someAsync@call@data"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package denalijsontest
import (
"testing"

fr "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/fileresolver"
mjparse "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/parse"
mjwrite "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/write"
"github.com/stretchr/testify/require"
Expand All @@ -12,11 +13,10 @@ func TestWriteScenario(t *testing.T) {
contents, err := loadExampleFile("example.scen.json")
require.Nil(t, err)

p := mjparse.Parser{
FileResolver: mjparse.NewDefaultFileResolver().ReplacePath(
p := mjparse.NewParser(
fr.NewDefaultFileResolver().ReplacePath(
"smart-contract.wasm",
"exampleFile.txt"),
}
"exampleFile.txt"))

scenario, parseErr := p.ParseScenarioFile(contents)
require.Nil(t, parseErr)
Expand Down
8 changes: 4 additions & 4 deletions test-util/denali/json/integrationTests/parseWriteTest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

fr "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/fileresolver"
mjparse "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/parse"
mjwrite "github.com/Dharitri-org/drtg-vm-util/test-util/denali/json/write"
"github.com/stretchr/testify/require"
Expand All @@ -30,11 +31,10 @@ func TestWriteTest(t *testing.T) {
contents, err := loadExampleFile("example.test.json")
require.Nil(t, err)

p := mjparse.Parser{
FileResolver: mjparse.NewDefaultFileResolver().ReplacePath(
p := mjparse.NewParser(
fr.NewDefaultFileResolver().ReplacePath(
"smart-contract.wasm",
"exampleFile.txt"),
}
"exampleFile.txt"))

testTopLevel, parseErr := p.ParseTestFile(contents)
require.Nil(t, parseErr)
Expand Down
Loading

0 comments on commit 401dcb1

Please sign in to comment.