Skip to content

Commit 0657ccf

Browse files
authored
Merge pull request #928 from multiversx/timestamps-ms-blockchain-hooks
add blockchain hooks for timestamps in millis
2 parents 5a3f382 + 7c2a78b commit 0657ccf

File tree

99 files changed

+11852
-690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+11852
-690
lines changed

executor/vmHooks.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

executor/wrapper/wrapperVMHooks.go

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ require (
1111
github.com/multiversx/mx-chain-core-go v1.3.2-0.20250520074139-18b645ad397a
1212
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250520075055-8ab2a164945d
1313
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250520074859-b2faf3c90273
14-
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250520075713-734e46b4c66d
14+
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250617131039-b09f258a9f6c
1515
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250520075958-65fd4c7bcaae
16-
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250520075408-c94bee9ee163
16+
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250604100541-1efc3d1b1314
1717
github.com/multiversx/mx-components-big-int v1.0.1-0.20250218162530-b4e4d7442408
1818
github.com/pelletier/go-toml v1.9.3
1919
github.com/stretchr/testify v1.8.1

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250520075055-8ab2a164945d h
8989
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250520075055-8ab2a164945d/go.mod h1:yekQt4uB5LYXtimbhpdUbnFexjucWrQG/t+AX55bdM8=
9090
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250520074859-b2faf3c90273 h1:1I2CgGDAMINxrKI6yzSP/Y6Wow2YUmqegUXcltpGXQA=
9191
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250520074859-b2faf3c90273/go.mod h1:M/uRv1kpmkzxS5HsgofdRcOHzzvagD7nTmFqiPKt89U=
92-
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250520075713-734e46b4c66d h1:BEJHmDMqoDzgNWx/jWn191WoSHLCIQmKszyJGEYWlyA=
93-
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250520075713-734e46b4c66d/go.mod h1:/bgycTrJGk6n6VlgW+onXRQKiCM3GFM+INENvj/PRgU=
92+
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250617131039-b09f258a9f6c h1:FiEuVVRJdFZZQ6YX+sx6GAU90LlscfZKKpxV2JVvt0w=
93+
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250617131039-b09f258a9f6c/go.mod h1:MAnOkKa27CXLwDPLFcYOGpZv8JVGe/CDKHT0TTtXHXM=
9494
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250520075958-65fd4c7bcaae h1:wgiIjyoynLQPs8QkEOXjAU8AoZlLA5w4rWPykLS2BSo=
9595
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250520075958-65fd4c7bcaae/go.mod h1:uiXDLvpznajMubl+OBhODo6jmtwo8kyUF9iujEhOIgI=
96-
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250520075408-c94bee9ee163 h1:I6WEqu3ysY41nRV7mUvdCsKyuBZlHyKngIjW4ncEcLI=
97-
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250520075408-c94bee9ee163/go.mod h1:HlpJgCTYVvHE1nrEJLIsR/AJx0gqzg3m+qdJwf7jOjU=
96+
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250604100541-1efc3d1b1314 h1:C2nlGnUyAoP2dBOEXBYwt7KXAv96m5tl3l2H208NVoA=
97+
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250604100541-1efc3d1b1314/go.mod h1:HlpJgCTYVvHE1nrEJLIsR/AJx0gqzg3m+qdJwf7jOjU=
9898
github.com/multiversx/mx-components-big-int v1.0.1-0.20250218162530-b4e4d7442408 h1:FbpVQJg14ry25DiBBZIvBoKiSrTHWkUSlYMOOW/iQJQ=
9999
github.com/multiversx/mx-components-big-int v1.0.1-0.20250218162530-b4e4d7442408/go.mod h1:kcWw7hDe6cSz1wcBAqj/6sFH6ouSPsNeH9P7XlpZRcw=
100100
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=

integrationTests/json/scenariosFeatures_test.go

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package vmjsonintegrationtest
22

33
import (
4+
"path/filepath"
45
"testing"
56
)
67

@@ -15,6 +16,18 @@ func TestRustAllocFeatures(t *testing.T) {
1516
CheckNoError()
1617
}
1718

19+
func TestRustBarnardFeatures(t *testing.T) {
20+
// TODO: will get merged into basic-features after barnard mainnet release
21+
if testing.Short() {
22+
t.Skip("not a short test")
23+
}
24+
25+
ScenariosTest(t).
26+
Folder("features/barnard-features/scenarios").
27+
Run().
28+
CheckNoError()
29+
}
30+
1831
func TestRustBasicFeaturesLatest(t *testing.T) {
1932
if testing.Short() {
2033
t.Skip("not a short test")
@@ -28,6 +41,23 @@ func TestRustBasicFeaturesLatest(t *testing.T) {
2841
CheckNoError()
2942
}
3043

44+
func TestRustBasicFeaturesBarnard(t *testing.T) {
45+
if testing.Short() {
46+
t.Skip("not a short test")
47+
}
48+
49+
ScenariosTest(t).
50+
Folder("features/basic-features/scenarios").
51+
Exclude("features/basic-features/scenarios/storage_mapper_fungible_token.scen.json").
52+
Exclude("features/basic-features/scenarios/get_shard_of_address.scen.json").
53+
ReplacePath(
54+
"../output/basic-features.mxsc.json",
55+
filepath.Join(getTestRoot(), "features/basic-features/output/basic-features-barnard.mxsc.json"),
56+
).
57+
Run().
58+
CheckNoError()
59+
}
60+
3161
func TestRustBasicFeaturesNoSmallIntApi(t *testing.T) {
3262
if testing.Short() {
3363
t.Skip("not a short test")
@@ -84,7 +114,7 @@ func TestRustManagedMapFeatures(t *testing.T) {
84114
CheckNoError()
85115
}
86116

87-
func TestRustPayableFeaturesLatest(t *testing.T) {
117+
func TestRustPayableFeatures(t *testing.T) {
88118
if testing.Short() {
89119
t.Skip("not a short test")
90120
}
@@ -95,6 +125,26 @@ func TestRustPayableFeaturesLatest(t *testing.T) {
95125
CheckNoError()
96126
}
97127

128+
func TestRustPayableFeaturesBarnard(t *testing.T) {
129+
if testing.Short() {
130+
t.Skip("not a short test")
131+
}
132+
133+
// we run the exact same tests, but on a different compiled contract,
134+
// this contract uses the new "managedGetAllTransfersCallValue" VM hook,
135+
// which is only available in Barnard
136+
// this will become the only test
137+
138+
ScenariosTest(t).
139+
Folder("features/payable-features/scenarios").
140+
ReplacePath(
141+
"../output/payable-features.mxsc.json",
142+
filepath.Join(getTestRoot(), "features/payable-features/output/payable-features-barnard.mxsc.json"),
143+
).
144+
Run().
145+
CheckNoError()
146+
}
147+
98148
func TestRustComposability(t *testing.T) {
99149
ScenariosTest(t).
100150
Folder("features/composability/scenarios").
@@ -116,18 +166,10 @@ func TestTimelocks(t *testing.T) {
116166
CheckNoError()
117167
}
118168

119-
func TestForwarderTransfExec(t *testing.T) {
120-
ScenariosTest(t).
121-
Folder("features/composability/scenarios").
122-
File("forwarder_call_transf_exec_reject_nft.scen.json").
123-
Run().
124-
CheckNoError()
125-
}
126-
127-
func TestForwarderTransfExecMultiReject(t *testing.T) {
169+
func TestForwarderTransfExecFallibleMultiReject(t *testing.T) {
128170
ScenariosTest(t).
129171
Folder("features/composability/scenarios").
130-
File("forwarder_call_transf_exec_reject_multi_transfer.scen.json").
172+
File("forw_raw_transf_exec_fallible_multi_egld_reject.scen.json").
131173
Run().
132174
CheckNoError()
133175
}

integrationTests/json/scenariosTestCommon.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type ScenariosTestBuilder struct {
4040
folder string
4141
singleFile string
4242
exclusions []string
43+
pathReplacements map[string]string
4344
executorLogger executorwrapper.ExecutorLogger
4445
executorFactory executor.ExecutorAbstractFactory
4546
enableEpochsHandler vmcommon.EnableEpochsHandler
@@ -53,6 +54,7 @@ func ScenariosTest(t *testing.T) *ScenariosTestBuilder {
5354
t: t,
5455
folder: "",
5556
singleFile: "",
57+
pathReplacements: make(map[string]string),
5658
executorLogger: nil,
5759
executorFactory: nil,
5860
enableEpochsHandler: worldmock.EnableEpochsHandlerStubAllFlags(),
@@ -77,6 +79,13 @@ func (mtb *ScenariosTestBuilder) Exclude(path string) *ScenariosTestBuilder {
7779
return mtb
7880
}
7981

82+
// ReplacePath allows a test to override the path to a contract, as expressed in a mandos test.
83+
// This is very helpful when running the same scenarios on multiple contracts.
84+
func (fr *ScenariosTestBuilder) ReplacePath(pathInTest, actualPath string) *ScenariosTestBuilder {
85+
fr.pathReplacements[pathInTest] = actualPath
86+
return fr
87+
}
88+
8089
// WithExecutorLogs sets a StringLogger
8190
func (mtb *ScenariosTestBuilder) WithExecutorLogs() *ScenariosTestBuilder {
8291
mtb.executorLogger = executorwrapper.NewStringLogger()
@@ -129,9 +138,14 @@ func (mtb *ScenariosTestBuilder) Run() *ScenariosTestBuilder {
129138

130139
scenarioExecutor.World.EnableEpochsHandler = mtb.enableEpochsHandler
131140

141+
fileResolver := scenio.NewDefaultFileResolver()
142+
for pathInTest, actualPath := range mtb.pathReplacements {
143+
fileResolver.ReplacePath(pathInTest, actualPath)
144+
}
145+
132146
runner := scenio.NewScenarioController(
133147
scenarioExecutor,
134-
scenio.NewDefaultFileResolver(),
148+
fileResolver,
135149
vmBuilder.GetVMType(),
136150
)
137151

mock/context/blockChainHookStub.go

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@ var _ vmcommon.BlockchainHook = (*BlockchainHookStub)(nil)
1111

1212
// BlockchainHookStub is used in tests to check that interface methods were called
1313
type BlockchainHookStub struct {
14-
NewAddressCalled func(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
15-
GetStorageDataCalled func(accountsAddress []byte, index []byte) ([]byte, uint32, error)
16-
GetBlockHashCalled func(nonce uint64) ([]byte, error)
17-
LastNonceCalled func() uint64
18-
LastRoundCalled func() uint64
19-
LastTimeStampCalled func() uint64
20-
LastRandomSeedCalled func() []byte
21-
LastEpochCalled func() uint32
22-
GetStateRootHashCalled func() []byte
23-
CurrentNonceCalled func() uint64
24-
CurrentRoundCalled func() uint64
25-
CurrentTimeStampCalled func() uint64
26-
CurrentRandomSeedCalled func() []byte
27-
CurrentEpochCalled func() uint32
28-
RoundTimeCalled func() uint64
29-
EpochStartBlockTimeStampCalled func() uint64
30-
EpochStartBlockNonceCalled func() uint64
31-
EpochStartBlockRoundCalled func() uint64
14+
NewAddressCalled func(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
15+
GetStorageDataCalled func(accountsAddress []byte, index []byte) ([]byte, uint32, error)
16+
GetBlockHashCalled func(nonce uint64) ([]byte, error)
17+
LastNonceCalled func() uint64
18+
LastRoundCalled func() uint64
19+
LastTimeStampCalled func() uint64
20+
LastTimeStampMsCalled func() uint64
21+
LastRandomSeedCalled func() []byte
22+
LastEpochCalled func() uint32
23+
GetStateRootHashCalled func() []byte
24+
CurrentNonceCalled func() uint64
25+
CurrentRoundCalled func() uint64
26+
CurrentTimeStampCalled func() uint64
27+
CurrentTimeStampMsCalled func() uint64
28+
CurrentRandomSeedCalled func() []byte
29+
CurrentEpochCalled func() uint32
30+
RoundTimeCalled func() uint64
31+
EpochStartBlockTimeStampMsCalled func() uint64
32+
EpochStartBlockNonceCalled func() uint64
33+
EpochStartBlockRoundCalled func() uint64
3234

3335
ProcessBuiltInFunctionCalled func(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
3436
GetBuiltinFunctionNamesCalled func() vmcommon.FunctionNames
@@ -94,6 +96,14 @@ func (b *BlockchainHookStub) LastTimeStamp() uint64 {
9496
return 0
9597
}
9698

99+
// LastTimeStampMs mocked method
100+
func (b *BlockchainHookStub) LastTimeStampMs() uint64 {
101+
if b.LastTimeStampMsCalled != nil {
102+
return b.LastTimeStampMsCalled()
103+
}
104+
return 0
105+
}
106+
97107
// LastRandomSeed mocked method
98108
func (b *BlockchainHookStub) LastRandomSeed() []byte {
99109
if b.LastRandomSeedCalled != nil {
@@ -142,6 +152,14 @@ func (b *BlockchainHookStub) CurrentTimeStamp() uint64 {
142152
return 0
143153
}
144154

155+
// CurrentTimeStampMs mocked method
156+
func (b *BlockchainHookStub) CurrentTimeStampMs() uint64 {
157+
if b.CurrentTimeStampMsCalled != nil {
158+
return b.CurrentTimeStampMsCalled()
159+
}
160+
return 0
161+
}
162+
145163
// CurrentRandomSeed mocked method
146164
func (b *BlockchainHookStub) CurrentRandomSeed() []byte {
147165
if b.CurrentRandomSeedCalled != nil {
@@ -166,10 +184,10 @@ func (b *BlockchainHookStub) RoundTime() uint64 {
166184
return 0
167185
}
168186

169-
// EpochStartBlockTimeStamp mocked method
170-
func (b *BlockchainHookStub) EpochStartBlockTimeStamp() uint64 {
171-
if b.EpochStartBlockTimeStampCalled != nil {
172-
return b.EpochStartBlockTimeStampCalled()
187+
// EpochStartBlockTimeStampMs mocked method
188+
func (b *BlockchainHookStub) EpochStartBlockTimeStampMs() uint64 {
189+
if b.EpochStartBlockTimeStampMsCalled != nil {
190+
return b.EpochStartBlockTimeStampMsCalled()
173191
}
174192
return 0
175193
}

mock/context/executorMockFunc.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

0 commit comments

Comments
 (0)