Skip to content

Commit

Permalink
Merge branch 'main' into blocks-mined-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters authored Oct 11, 2023
2 parents c14542e + 6bbb60f commit d9f7c0b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ ENV METRICS_PORT $METRICS_PORT
EXPOSE $PORT $METRICS_PORT 9229 9230

USER node
WORKDIR /usr/src/app/packages/api

CMD [ "node", "packages/api/dist/main.js" ]
CMD [ "node", "dist/main.js" ]
5 changes: 4 additions & 1 deletion packages/app/src/components/contract/ContractInfoTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
</div>
<div v-else class="functions-dropdown-container">
<div class="function-dropdown-spacer">
<span class="function-type-title">{{ t("contract.abiInteraction.method.read.name") }}</span>
<div class="metamask-button-container">
<span class="function-type-title">{{ t("contract.abiInteraction.method.read.name") }}</span>
<ConnectMetamaskButton />
</div>
<FunctionDropdown
v-for="(item, index) in readFunctions"
:key="item.name"
Expand Down
6 changes: 5 additions & 1 deletion packages/app/src/composables/useContractInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export default (context = useContext()) => {
isRequestFailed.value = false;
response.value = undefined;
errorMessage.value = null;
const signer = new zkSyncSdk.Provider(context.currentNetwork.value.rpcUrl);
let signer: zkSyncSdk.Provider | zkSyncSdk.Signer = new zkSyncSdk.Provider(context.currentNetwork.value.rpcUrl);
if (walletAddress.value !== null) {
// If connected to a wallet, use the signer so 'msg.sender' is correctly populated downstream
signer = await getL2Signer();
}
const contract = new ethers.Contract(address, [abiFragment], signer!);
const res = (
await contract[abiFragment.name](...Object.entries(params).map(([, inputValue]) => inputValue)).catch(
Expand Down
21 changes: 21 additions & 0 deletions packages/app/tests/composables/useContractInteraction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ describe("useContractInteraction:", () => {
expect(errorMessage.value).toEqual("An error occurred");
mock.mockRestore();
});
it("uses Signer when wallet address is not null", async () => {
const mockGetL2Signer = vi.fn(async () => undefined);
const walletMock = useWalletMock({
getL2Signer: mockGetL2Signer,
address: { value: "0x0cc725e6ba24e7db79f62f22a7994a8ee33adc1b" },
});
const { readFunction } = useContractInteraction();
await readFunction("0x0cc725e6ba24e7db79f62f22a7994a8ee33adc1b", abiFragment, {});
expect(mockGetL2Signer).toHaveBeenCalled();
mockGetL2Signer.mockRestore();
walletMock.mockRestore();
});
it("uses Provider when wallet address is null", async () => {
const mockGetL2Signer = vi.fn(async () => undefined);
const walletMock = useWalletMock({ getL2Signer: mockGetL2Signer });
const { readFunction } = useContractInteraction();
await readFunction("0x0cc725e6ba24e7db79f62f22a7994a8ee33adc1b", abiFragment, {});
expect(mockGetL2Signer).not.toHaveBeenCalled();
mockGetL2Signer.mockRestore();
walletMock.mockRestore();
});
});
describe("writeFunction:", () => {
beforeEach(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ ENV PORT $PORT
EXPOSE $PORT 9229 9230

USER node
WORKDIR /usr/src/app/packages/worker

CMD [ "node", "packages/worker/dist/main.js" ]
CMD [ "node", "dist/main.js" ]
4 changes: 2 additions & 2 deletions scripts/setup-hyperchain-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as dotenv from "dotenv";
import { parse as parseConnectionString } from "pg-connection-string";

const buildAppConfig = (zkSyncEnvs: { [key: string]: string }) => ({
networks: {
networks: [{
apiUrl: "http://localhost:3020",
verificationApiUrl: zkSyncEnvs.API_CONTRACT_VERIFICATION_URL || "",
hostnames: ["localhost"],
Expand All @@ -18,7 +18,7 @@ const buildAppConfig = (zkSyncEnvs: { [key: string]: string }) => ({
name: zkSyncEnvs.CHAIN_ETH_ZKSYNC_NETWORK || "",
published: true,
rpcUrl: zkSyncEnvs.API_WEB3_JSON_RPC_HTTP_URL || "",
}
}]
});

const buildWorkerConfig = (zkSyncEnvs: { [key: string]: string }) => {
Expand Down

0 comments on commit d9f7c0b

Please sign in to comment.