Testing

SDK Testing

The SDK uses two types of tests, End-to-End (E2E) and unit tests, located under the tests folder.

Unit Tests

Unit tests are meant to test the output of a function in the SDK with the provided input. For example, we can test whether an account address is valid.

test("account address is valid", () => {
  const { valid } = AccountAddress.isValid({
    input: "0x1",
  });
  expect(valid).toBe(true);
});

Can check here for the SDK unit tests

E2E Tests

End-to-end tests are meant to test the end-to-end operations starting from the SDK methods through to the blockchain.

For example, to test if a transaction has been submitted, we start with building a transaction payload that the SDK expects, submit the request to the REST API, and fetch the transaction data to make sure it has been fully committed to the blockchain.

test("transaction submission", async () => {
  const transaction = await endless.transaction.build.simple({
    sender: sender.accountAddress,
    data: {
      function: `0x1::endless_account::transfer`, // replace with your application's transaction
      functionArguments: [receiver.accountAddress, 1],
    },
  });
  const response = await endless.signAndSubmitTransaction({
    signer: sender,
    transaction,
  });
  await endless.waitForTransaction({
    transactionHash: response.hash,
  });
  expect(response.success).toBe(true);
});

Can check here for the SDK e2e tests

Integration Tests

The SDK provides an easy way to run integration tests by spinning up a local node and running tests against it. For example, one can build their integration tests against a local node with the SDK like below:

Last updated