Skip to content

fix(connector-ethereum): additional properties to deployContract does not throw error #3507

@ashnashahgrover

Description

@ashnashahgrover

Describe the bug

The deployContract function in cactus-plugin-ledger-connector-ethereum takes DeployContractV1Request as an argument, which already declares additional properties as forbidden in the Open API spec as can be seen here:

"DeployContractV1Request": {
        "type": "object",
        "required": ["web3SigningCredential", "contract"],
        **"additionalProperties": false,**
        "properties": {
          "web3SigningCredential": {
            "$ref": "#/components/schemas/Web3SigningCredential"
          },
          "contract": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ContractJsonDefinition"
              },
              {
                "$ref": "#/components/schemas/ContractKeychainDefinition"
              }
            ],
            "nullable": false
          },
          "constructorArgs": {
            "description": "The list of arguments to pass in to the constructor of the contract being deployed.",
            "type": "array",
            "default": [],
            "items": {}
          },
          "gasConfig": {
            "$ref": "#/components/schemas/GasTransactionConfig"
          },
          "value": {
            "type": "string",
            "description": "Ether balance to send on deployment.",
            "nullable": false
          }
        }
      }

However in various tests that input additional properties, and expect an error to be thrown, the test actually passes.

To Reproduce

Run the test beginning on this line.

The test should throw an error, but it passes without an error.

Expected behavior

The test should throw an error saying additional properties are forbidden.

Logs/Stack traces
Run the test this way, with the fail statement commented out, as that was actually causing the test to fail rather than the additional parameters provided (fake: 4 is the additional parameter):

  test("deployContract with additional parameters should fail", async () => {
    try {
      const result = await apiClient.deployContract({
        contract: {
          contractJSON: HelloWorldContractJson,
        },
        web3SigningCredential: {
          ethAccount: WHALE_ACCOUNT_ADDRESS,
          secret: "",
          type: Web3SigningCredentialType.GethKeychainPassword,
        },
        gas: 1000000,
        fake: 4,
      } as DeployContractV1Request);
      // fail("Expected deployContract call to fail but it succeeded.");
      console.log("deployContract actually returned a response", result);
    } catch (error) {
      console.log("deployContract failed as expected");
    }
  });

And it will return this in the log:

deployContract actually returned a response {
status: 200,
statusText: 'OK',
headers: Object [AxiosHeaders] {
'x-powered-by': 'Express',
'content-type': 'application/json; charset=utf-8',
'content-length': '993',
etag: 'W/"3e1-Cc+on/RU7altdwH6OGOLX2/wWiM"',
date: 'Tue, 03 Sep 2024 01:00:19 GMT',
connection: 'close'
},
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
...

Full log here:
testPassed.txt

Hyperledger Cactus Plugins/Connectors Used

  • Ethereum

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4Priority 4: LowTestsAnything related to tests be that automatic or manual, integration or unit, etc.bugSomething isn't workinggood-first-issueGood for newcomersgood-first-issue-400-expert

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions