From a1b5faadb68c8093d80ad546dd433b9b936b483a Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 24 Apr 2024 14:38:31 +0300 Subject: [PATCH 1/6] new endpoint --- README.md | 52 +++++++++++++++++++++++++++++++++++ go.mod | 10 +++---- go.sum | 20 +++++++------- pkg/facade/interface.go | 1 + pkg/facade/simulatorFacade.go | 15 ++++++++++ pkg/proxy/api/endpoints.go | 33 +++++++++++++++++----- pkg/proxy/api/interface.go | 1 + 7 files changed, 110 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 3e2d504a..093b3a24 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,58 @@ Example: ``` +### `POST /simulator/set-state-overwrite` + +This endpoint allows you to set the entire state (also will clean the old state of provided accounts) for a provided list of addresses. + +##### Request +- **Method:** POST +- **Path:** `/simulator/set-state` + + +##### Request Body +The request body should be a JSON object representing an array of object with the next format. + +Example: +``` +[ + { + "address": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "balance": "431271308732096033771131", + "code": "0061736d010000000129086000006000017f60027f7f017f60027f7f0060017f0060037f7f7f017f60037f7f7f0060017f017f0290020b03656e7619626967496e74476574556e7369676e6564417267756d656e74000303656e760f6765744e756d417267756d656e7473000103656e760b7369676e616c4572726f72000303656e76126d42756666657253746f726167654c6f6164000203656e76176d427566666572546f426967496e74556e7369676e6564000203656e76196d42756666657246726f6d426967496e74556e7369676e6564000203656e76136d42756666657253746f7261676553746f7265000203656e760f6d4275666665725365744279746573000503656e760e636865636b4e6f5061796d656e74000003656e7614626967496e7446696e697368556e7369676e6564000403656e7609626967496e744164640006030b0a010104070301000000000503010003060f027f0041a080080b7f0041a080080b074607066d656d6f7279020004696e697400110667657453756d00120361646400130863616c6c4261636b00140a5f5f646174615f656e6403000b5f5f686561705f6261736503010aca010a0e01017f4100100c2200100020000b1901017f419c8008419c800828020041016b220036020020000b1400100120004604400f0b4180800841191002000b16002000100c220010031a2000100c220010041a20000b1401017f100c2202200110051a2000200210061a0b1301017f100c220041998008410310071a20000b1401017f10084101100d100b210010102000100f0b0e0010084100100d1010100e10090b2201037f10084101100d100b210110102202100e220020002001100a20022000100f0b0300010b0b2f0200418080080b1c77726f6e67206e756d626572206f6620617267756d656e747373756d00419c80080b049cffffff", + "rootHash": "76cr5Jhn6HmBcDUMIzikEpqFgZxIrOzgNkTHNatXzC4=", + "codeMetadata": "BQY=", + "codeHash": "n9EviPlHS6EV+3Xp0YqP28T0IUfeAFRFBIRC1Jw6pyU=", + "developerReward": "5401004999998", + "ownerAddress": "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97", + "keys": { + "73756d": "0a" + } + }, + { + "address": "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97", + "balance": "431271308732096033771131" + } + // ...additional state for another address +] +``` + + +##### Response +- **Status Codes:** + - `200 OK`: State set successfully. + - `404 Bad Request`: Invalid request parameters. + +#### Response Body +```json +{ + "data": {}, + "error": "", + "code": "successful" +} +``` + + ### `POST /simulator/add-keys` This endpoint allows you to add new validator private keys in the multi key handler. diff --git a/go.mod b/go.mod index e2b22312..bf30e51e 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-core-go v1.2.19 - github.com/multiversx/mx-chain-go v1.7.9-0.20240411072641-1658254d294b + github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d github.com/multiversx/mx-chain-logger-go v1.0.14 github.com/multiversx/mx-chain-proxy-go v1.1.47 github.com/pelletier/go-toml v1.9.3 @@ -170,13 +170,13 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.14.0 // indirect + golang.org/x/crypto v0.21.0 // indirect golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.21.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.13.0 // indirect gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect diff --git a/go.sum b/go.sum index 000c90a8..5e1ec452 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKD github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk= -github.com/multiversx/mx-chain-go v1.7.9-0.20240411072641-1658254d294b h1:7wPvUxCPml/dn8Ows6LiOPZ0LUgfcpB0BGVUQwztVYw= -github.com/multiversx/mx-chain-go v1.7.9-0.20240411072641-1658254d294b/go.mod h1:egvBH/R9pwYGHd8KsIw/8B3GXE4z0kkegnKKTk4gAL0= +github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d h1:tcnIH3UjFVQdGQDUt5RJyoeBher8Xhwk2f+9RfqqwNo= +github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d/go.mod h1:HVM/n4nTxKbReMacG5XcQifNYSfwUZtcYx7zTCPR8JE= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= github.com/multiversx/mx-chain-proxy-go v1.1.47 h1:9oebF9PXbfP9QMJw0pjARbnEIwS8wRigOYn8+po1W8g= @@ -637,8 +637,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -684,8 +684,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -742,8 +742,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -758,8 +758,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/pkg/facade/interface.go b/pkg/facade/interface.go index 3e06e89a..d24b52c4 100644 --- a/pkg/facade/interface.go +++ b/pkg/facade/interface.go @@ -8,6 +8,7 @@ type SimulatorHandler interface { GenerateBlocks(numOfBlocks int) error SetKeyValueForAddress(address string, keyValueMap map[string]string) error SetStateMultiple(stateSlice []*dtos.AddressState) error + RemoveAccounts(addresses []string) error AddValidatorKeys(validatorsPrivateKeys [][]byte) error GenerateBlocksUntilEpochIsReached(targetEpoch int32) error ForceResetValidatorStatisticsCache() error diff --git a/pkg/facade/simulatorFacade.go b/pkg/facade/simulatorFacade.go index 46ddc966..dcf898fd 100644 --- a/pkg/facade/simulatorFacade.go +++ b/pkg/facade/simulatorFacade.go @@ -48,6 +48,21 @@ func (sf *simulatorFacade) SetStateMultiple(stateSlice []*dtos.AddressState) err return sf.simulator.SetStateMultiple(stateSlice) } +// SetStateMultipleOverwrite will set the entire state for the provided address and cleanup the old state of the provided addresses +func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressState) error { + accounts := make([]string, 0) + for _, state := range stateSlice { + accounts = append(accounts, state.Address) + } + + err := sf.simulator.RemoveAccounts(accounts) + if err != nil { + return err + } + + return sf.simulator.SetStateMultiple(stateSlice) +} + // AddValidatorKeys will add the validator keys in the multi key handler func (sf *simulatorFacade) AddValidatorKeys(validators *dtoc.ValidatorKeys) error { validatorsPrivateKeys := make([][]byte, 0, len(validators.PrivateKeysBase64)) diff --git a/pkg/proxy/api/endpoints.go b/pkg/proxy/api/endpoints.go index d0aa36dd..18b8f847 100644 --- a/pkg/proxy/api/endpoints.go +++ b/pkg/proxy/api/endpoints.go @@ -14,13 +14,14 @@ import ( ) const ( - generateBlocksEndpoint = "/simulator/generate-blocks/:num" - generateBlockUnitEpochReached = "/simulator/generate-blocks-until-epoch-reached/:epoch" - initialWalletsEndpoint = "/simulator/initial-wallets" - setKeyValuesEndpoint = "/simulator/address/:address/set-state" - setStateMultipleEndpoint = "/simulator/set-state" - addValidatorsKeys = "/simulator/add-keys" - forceUpdateValidatorStatistics = "/simulator/force-reset-validator-statistics" + generateBlocksEndpoint = "/simulator/generate-blocks/:num" + generateBlockUnitEpochReached = "/simulator/generate-blocks-until-epoch-reached/:epoch" + initialWalletsEndpoint = "/simulator/initial-wallets" + setKeyValuesEndpoint = "/simulator/address/:address/set-state" + setStateMultipleEndpoint = "/simulator/set-state" + setStateMultipleOverwriteEndpoint = "/simulator/set-state-overwrite" + addValidatorsKeys = "/simulator/add-keys" + forceUpdateValidatorStatistics = "/simulator/force-reset-validator-statistics" ) type endpointsProcessor struct { @@ -46,6 +47,7 @@ func (ep *endpointsProcessor) ExtendProxyServer(httpServer *http.Server) error { ws.GET(initialWalletsEndpoint, ep.initialWallets) ws.POST(setKeyValuesEndpoint, ep.setKeyValue) ws.POST(setStateMultipleEndpoint, ep.setStateMultiple) + ws.POST(setStateMultipleOverwriteEndpoint, ep.setStateMultipleOverwrite) ws.POST(addValidatorsKeys, ep.addValidatorKeys) ws.POST(forceUpdateValidatorStatistics, ep.forceUpdateValidatorStatistics) @@ -142,6 +144,23 @@ func (ep *endpointsProcessor) setStateMultiple(c *gin.Context) { shared.RespondWith(c, http.StatusOK, gin.H{}, "", data.ReturnCodeSuccess) } +func (ep *endpointsProcessor) setStateMultipleOverwrite(c *gin.Context) { + var stateSlice []*dtos.AddressState + err := c.ShouldBindJSON(&stateSlice) + if err != nil { + shared.RespondWithBadRequest(c, fmt.Sprintf("invalid state structure, error: %s", err.Error())) + return + } + + err = ep.facade.SetStateMultipleOverwrite(stateSlice) + if err != nil { + shared.RespondWithBadRequest(c, fmt.Sprintf("cannot set state, error: %s", err.Error())) + return + } + + shared.RespondWith(c, http.StatusOK, gin.H{}, "", data.ReturnCodeSuccess) +} + func (ep *endpointsProcessor) addValidatorKeys(c *gin.Context) { validatorsKeys := &dtosc.ValidatorKeys{} diff --git a/pkg/proxy/api/interface.go b/pkg/proxy/api/interface.go index e520ac8b..44e9c730 100644 --- a/pkg/proxy/api/interface.go +++ b/pkg/proxy/api/interface.go @@ -11,6 +11,7 @@ type SimulatorFacade interface { GetInitialWalletKeys() *dtos.InitialWalletKeys SetKeyValueForAddress(address string, keyValueMap map[string]string) error SetStateMultiple(stateSlice []*dtos.AddressState) error + SetStateMultipleOverwrite(stateSlice []*dtos.AddressState) error AddValidatorKeys(validators *dtosc.ValidatorKeys) error GenerateBlocksUntilEpochIsReached(targetEpoch int32) error ForceUpdateValidatorStatistics() error From 6af260ba4c02b2c900a36a17240ac14107141d46 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 24 Apr 2024 14:43:33 +0300 Subject: [PATCH 2/6] small fixes --- README.md | 2 +- pkg/facade/simulatorFacade.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 093b3a24..07233fdc 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ Example: ### `POST /simulator/set-state-overwrite` -This endpoint allows you to set the entire state (also will clean the old state of provided accounts) for a provided list of addresses. +This endpoint allows you to set the entire state (also will clean the old state of the provided accounts) for a provided list of addresses. ##### Request - **Method:** POST diff --git a/pkg/facade/simulatorFacade.go b/pkg/facade/simulatorFacade.go index dcf898fd..20f73290 100644 --- a/pkg/facade/simulatorFacade.go +++ b/pkg/facade/simulatorFacade.go @@ -48,7 +48,7 @@ func (sf *simulatorFacade) SetStateMultiple(stateSlice []*dtos.AddressState) err return sf.simulator.SetStateMultiple(stateSlice) } -// SetStateMultipleOverwrite will set the entire state for the provided address and cleanup the old state of the provided addresses +// SetStateMultipleOverwrite will set the entire state for the provided address and cleanup the old state of the provided addresses func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressState) error { accounts := make([]string, 0) for _, state := range stateSlice { From 5385272a5f52be0f3fc059de50a04a21f43815cb Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 24 Apr 2024 14:59:51 +0300 Subject: [PATCH 3/6] new proxy version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index bf30e51e..0301872e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/multiversx/mx-chain-core-go v1.2.19 github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d github.com/multiversx/mx-chain-logger-go v1.0.14 - github.com/multiversx/mx-chain-proxy-go v1.1.47 + github.com/multiversx/mx-chain-proxy-go v1.1.48 github.com/pelletier/go-toml v1.9.3 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 diff --git a/go.sum b/go.sum index 5e1ec452..eb72a9f1 100644 --- a/go.sum +++ b/go.sum @@ -405,8 +405,8 @@ github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d h1:tcnIH3 github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d/go.mod h1:HVM/n4nTxKbReMacG5XcQifNYSfwUZtcYx7zTCPR8JE= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= -github.com/multiversx/mx-chain-proxy-go v1.1.47 h1:9oebF9PXbfP9QMJw0pjARbnEIwS8wRigOYn8+po1W8g= -github.com/multiversx/mx-chain-proxy-go v1.1.47/go.mod h1:Ax+80b1qynepkZSxrz8QB3AO00JAL3svaLasMTE6Lh0= +github.com/multiversx/mx-chain-proxy-go v1.1.48 h1:gmunv+2oimIN8ejlVAN7eWP7mt38So1WvsyiR3+94SU= +github.com/multiversx/mx-chain-proxy-go v1.1.48/go.mod h1:Ax+80b1qynepkZSxrz8QB3AO00JAL3svaLasMTE6Lh0= github.com/multiversx/mx-chain-scenario-go v1.4.3 h1:9xeVB8TOsolXS4YEr1CZ/VZr5Qk0X+nde8nRGnxJICo= github.com/multiversx/mx-chain-scenario-go v1.4.3/go.mod h1:Bd7/Xs3mWM6pX/REHK5dfpf3MUfjMZ7li09cfCxg2ac= github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdReD/tKBJj10JbxXvaE= From d4c435aafb9316eea100929404858170b589c3a8 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 24 Apr 2024 15:06:00 +0300 Subject: [PATCH 4/6] fix unit tests --- testscommon/simulatorHandlerMock.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testscommon/simulatorHandlerMock.go b/testscommon/simulatorHandlerMock.go index 8c597322..fc550c8d 100644 --- a/testscommon/simulatorHandlerMock.go +++ b/testscommon/simulatorHandlerMock.go @@ -11,6 +11,16 @@ type SimulatorHandlerMock struct { AddValidatorKeysCalled func(validatorsPrivateKeys [][]byte) error GenerateBlocksUntilEpochIsReachedCalled func(targetEpoch int32) error ForceResetValidatorStatisticsCacheCalled func() error + RemoveAccountsCalled func(addresses []string) error +} + +// RemoveAccounts - +func (mock *SimulatorHandlerMock) RemoveAccounts(addresses []string) error { + if mock.RemoveAccountsCalled != nil { + return mock.RemoveAccountsCalled(addresses) + } + + return nil } // GetInitialWalletKeys - From 1db121410fc3a19e59f257793076b774939bbb28 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 24 Apr 2024 17:48:49 +0300 Subject: [PATCH 5/6] proper tag --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 0301872e..73b6343c 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.20 require ( github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.19 - github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d + github.com/multiversx/mx-chain-core-go v1.2.20 + github.com/multiversx/mx-chain-go v1.7.9 github.com/multiversx/mx-chain-logger-go v1.0.14 github.com/multiversx/mx-chain-proxy-go v1.1.48 github.com/pelletier/go-toml v1.9.3 diff --git a/go.sum b/go.sum index eb72a9f1..90b9050f 100644 --- a/go.sum +++ b/go.sum @@ -395,14 +395,14 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= -github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= -github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20 h1:jOQ10LxxUqECnuqUYeBBT6VoZcpJDdYgOvsSGtifDdI= +github.com/multiversx/mx-chain-core-go v1.2.20/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk= -github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d h1:tcnIH3UjFVQdGQDUt5RJyoeBher8Xhwk2f+9RfqqwNo= -github.com/multiversx/mx-chain-go v1.7.9-0.20240424111810-ebb386a3356d/go.mod h1:HVM/n4nTxKbReMacG5XcQifNYSfwUZtcYx7zTCPR8JE= +github.com/multiversx/mx-chain-go v1.7.9 h1:2b6ef9ggIS3Mgf38wn+Z71/Fy0enMTCa/sp9F4faNFk= +github.com/multiversx/mx-chain-go v1.7.9/go.mod h1:HwklJGQfMpv/yyF4oLpxjwdKCawspv1JjdgezlWBpRQ= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= github.com/multiversx/mx-chain-proxy-go v1.1.48 h1:gmunv+2oimIN8ejlVAN7eWP7mt38So1WvsyiR3+94SU= From 3b3247f27572b2e49f30316f78c5643e0959b384 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 25 Apr 2024 14:55:57 +0300 Subject: [PATCH 6/6] fixes after second review --- pkg/facade/simulatorFacade.go | 2 +- pkg/proxy/api/endpoints.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/facade/simulatorFacade.go b/pkg/facade/simulatorFacade.go index 20f73290..1b7b32f0 100644 --- a/pkg/facade/simulatorFacade.go +++ b/pkg/facade/simulatorFacade.go @@ -50,7 +50,7 @@ func (sf *simulatorFacade) SetStateMultiple(stateSlice []*dtos.AddressState) err // SetStateMultipleOverwrite will set the entire state for the provided address and cleanup the old state of the provided addresses func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressState) error { - accounts := make([]string, 0) + accounts := make([]string, 0, len(stateSlice)) for _, state := range stateSlice { accounts = append(accounts, state.Address) } diff --git a/pkg/proxy/api/endpoints.go b/pkg/proxy/api/endpoints.go index 18b8f847..41331ba3 100644 --- a/pkg/proxy/api/endpoints.go +++ b/pkg/proxy/api/endpoints.go @@ -154,7 +154,7 @@ func (ep *endpointsProcessor) setStateMultipleOverwrite(c *gin.Context) { err = ep.facade.SetStateMultipleOverwrite(stateSlice) if err != nil { - shared.RespondWithBadRequest(c, fmt.Sprintf("cannot set state, error: %s", err.Error())) + shared.RespondWithBadRequest(c, fmt.Sprintf("cannot overwrite state, error: %s", err.Error())) return }