-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E test to verify behavior on revert
Signed-off-by: Peter Broadhurst <[email protected]>
- Loading branch information
1 parent
c808a7c
commit d67a3b7
Showing
8 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"contracts":{"reverter.sol:Reverter":{"abi":[{"inputs":[],"name":"goBang","outputs":[],"stateMutability":"pure","type":"function"}],"bin":"608060405234801561001057600080fd5b5061011b806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063060846fb14602d575b600080fd5b60336035565b005b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040160659060c7565b60405180910390fd5b600082825260208201905092915050565b7f42616e6721000000000000000000000000000000000000000000000000000000600082015250565b600060b3600583606e565b915060bc82607f565b602082019050919050565b6000602082019050818103600083015260de8160a8565b905091905056fea26469706673582212204c5a121fa1ad563532a26d368380482d34f0eee629e860671f518ec7af2fc2c064736f6c63430008170033"}},"version":"0.8.23+commit.f704f362.Darwin.appleclang"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pragma solidity >=0.6.0 <0.9.0; | ||
|
||
contract Reverter { | ||
function goBang() pure public { | ||
revert("Bang!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package gateway | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/go-resty/resty/v2" | ||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/hyperledger/firefly/pkg/core" | ||
"github.com/hyperledger/firefly/test/e2e" | ||
"github.com/hyperledger/firefly/test/e2e/client" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type EthereumRevertTestSuite struct { | ||
suite.Suite | ||
testState *testState | ||
contractAddress string | ||
ethClient *resty.Client | ||
ethIdentity string | ||
abi *fftypes.JSONAny | ||
} | ||
|
||
func (suite *EthereumRevertTestSuite) SetupSuite() { | ||
suite.testState = beforeE2ETest(suite.T()) | ||
stack := e2e.ReadStack(suite.T()) | ||
stackState := e2e.ReadStackState(suite.T()) | ||
suite.ethClient = client.NewResty(suite.T()) | ||
suite.ethClient.SetBaseURL(fmt.Sprintf("http://localhost:%d", stack.Members[0].ExposedConnectorPort)) | ||
account := stackState.Accounts[0].(map[string]interface{}) | ||
suite.ethIdentity = account["address"].(string) | ||
suite.abi, suite.contractAddress = deployTestContractFromCompiledJSON(suite.T(), stack.Name, "reverter/reverter.json") | ||
} | ||
|
||
func (suite *EthereumRevertTestSuite) BeforeTest(suiteName, testName string) { | ||
suite.testState = beforeE2ETest(suite.T()) | ||
} | ||
|
||
func (suite *EthereumRevertTestSuite) AfterTest(suiteName, testName string) { | ||
// Important part of the test - the status of the operation must go to Failed - immediately. | ||
// We should not encounter an "Initialized" status | ||
e2e.VerifyOperationsAlreadyMarkedFailed(suite.T(), []*client.FireFlyClient{suite.testState.client1}, suite.testState.startTime) | ||
} | ||
|
||
func (suite *EthereumRevertTestSuite) TestRevertTransitionsToFailed() { | ||
defer suite.testState.Done() | ||
|
||
type generateInput struct { | ||
ABI *fftypes.JSONAny `json:"abi"` | ||
} | ||
inputBytes, err := json.Marshal(&generateInput{ABI: suite.abi}) | ||
assert.NoError(suite.T(), err) | ||
|
||
ffi := suite.testState.client1.GenerateFFIFromABI(suite.T(), &fftypes.FFIGenerationRequest{ | ||
Input: fftypes.JSONAnyPtrBytes(inputBytes), | ||
}) | ||
assert.NoError(suite.T(), err) | ||
var goBang *fftypes.FFIMethod | ||
for _, m := range ffi.Methods { | ||
if m.Name == "goBang" { | ||
goBang = m | ||
} | ||
} | ||
assert.NotNil(suite.T(), goBang) | ||
|
||
location := map[string]interface{}{ | ||
"address": suite.contractAddress, | ||
} | ||
locationBytes, _ := json.Marshal(location) | ||
invokeContractRequest := &core.ContractCallRequest{ | ||
Location: fftypes.JSONAnyPtrBytes(locationBytes), | ||
Method: goBang, | ||
Input: map[string]interface{}{}, | ||
} | ||
|
||
// Check we get the revert error all the way back through the API on the invoke, due to the gas estimation | ||
_, err = suite.testState.client1.InvokeContractMethod(suite.T(), invokeContractRequest, 500) | ||
assert.Regexp(suite.T(), "FF10111.*Bang!", err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters