diff --git a/packages/utils-evm/test/oapp.test.ts b/packages/utils-evm/test/oapp.test.ts new file mode 100644 index 000000000..a34ac4250 --- /dev/null +++ b/packages/utils-evm/test/oapp.test.ts @@ -0,0 +1,28 @@ +import { Contract } from "@ethersproject/contracts" +import { EndpointId } from "@layerzerolabs/lz-definitions" +import { expect } from "chai" +import { describe } from "mocha" +import sinon from "sinon" +import { createSetPeerConfigurable } from "../src/oapp" +import { isMisconfigured } from "../src/configurable" + +describe("oapp", () => { + describe("createSetPeerConfigurable", () => { + it("should return Configured if the current and desired values match", async () => { + const oapp = { + peers: sinon.stub().resolves("peer-not-set"), + setPeer: sinon.stub().resolves("okay"), + } + const configurable = createSetPeerConfigurable((_, endpointId) => `peer-on-${endpointId}`) + const state = await configurable(oapp as unknown as Contract, EndpointId.AAVEGOTCHI_TESTNET) + + expect(isMisconfigured(state)).to.be.true + expect(state.value).to.eql("peer-not-set") + expect(state.desiredValue).to.eql(`peer-on-${EndpointId.AAVEGOTCHI_TESTNET}`) + + const result = await state.configure?.() + + expect(result).to.eql("okay") + }) + }) +})