Skip to content

Commit a27fec8

Browse files
authored
Merge pull request #17 from rarimo/bugfix/crosschain-module
Fix zero address for cc module
2 parents d3e3672 + 4d5abd9 commit a27fec8

2 files changed

Lines changed: 36 additions & 27 deletions

File tree

contracts/core/subscription/modules/CrossChainModule.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ contract CrossChainModule is ICrossChainModule, BaseSubscriptionModule, Initiali
4444
}
4545

4646
function _setSubscriptionSynchronizer(address subscriptionSynchronizer_) internal virtual {
47-
_checkAddress(subscriptionSynchronizer_, "SubscriptionsSynchronizer");
48-
4947
_getCrossChainModuleStorage().subscriptionsSynchronizer = ISubscriptionsSynchronizer(
5048
subscriptionSynchronizer_
5149
);
@@ -59,13 +57,15 @@ contract CrossChainModule is ICrossChainModule, BaseSubscriptionModule, Initiali
5957
) internal virtual override(BaseSubscriptionModule) {
6058
super._extendSubscription(account_, duration_);
6159

62-
uint64 subscriptionStartTime_ = getSubscriptionStartTime(account_);
60+
if (address(_getCrossChainModuleStorage().subscriptionsSynchronizer) != address(0)) {
61+
uint64 subscriptionStartTime_ = getSubscriptionStartTime(account_);
6362

64-
_getCrossChainModuleStorage().subscriptionsSynchronizer.saveSubscriptionData(
65-
account_,
66-
subscriptionStartTime_,
67-
getSubscriptionEndTime(account_),
68-
subscriptionStartTime_ == uint64(block.timestamp)
69-
);
63+
_getCrossChainModuleStorage().subscriptionsSynchronizer.saveSubscriptionData(
64+
account_,
65+
subscriptionStartTime_,
66+
getSubscriptionEndTime(account_),
67+
subscriptionStartTime_ == uint64(block.timestamp)
68+
);
69+
}
7070
}
7171
}

test/core/subscription/modules/CrossChainModule.test.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ describe("CrossChainModule", () => {
4444
}),
4545
).to.be.revertedWithCustomError(crossChainModule, "NotInitializing");
4646
});
47-
48-
it("should get exception if try to initialize with zero address", async () => {
49-
const newCrossChainModule = await ethers.deployContract("CrossChainModuleMock");
50-
51-
await expect(
52-
newCrossChainModule.initialize({
53-
subscriptionsSynchronizer: ethers.ZeroAddress,
54-
}),
55-
)
56-
.to.be.revertedWithCustomError(newCrossChainModule, "ZeroAddr")
57-
.withArgs("SubscriptionsSynchronizer");
58-
});
5947
});
6048

6149
describe("#setSubscriptionSynchronizer", () => {
@@ -64,12 +52,6 @@ describe("CrossChainModule", () => {
6452

6553
await expect(tx).to.emit(crossChainModule, "SubscriptionSynchronizerUpdated").withArgs(FIRST);
6654
});
67-
68-
it("should get exception if try to set zero address", async () => {
69-
await expect(crossChainModule.setSubscriptionSynchronizer(ethers.ZeroAddress))
70-
.to.be.revertedWithCustomError(crossChainModule, "ZeroAddr")
71-
.withArgs("SubscriptionsSynchronizer");
72-
});
7355
});
7456

7557
describe("#extendSubscription", () => {
@@ -96,5 +78,32 @@ describe("CrossChainModule", () => {
9678
expect(await crossChainModule.hasActiveSubscription(FIRST)).to.be.true;
9779
expect(await crossChainModule.hasSubscriptionDebt(FIRST)).to.be.false;
9880
});
81+
82+
it("should correctly extend subscription and not sync data if synchronizer is zero address", async () => {
83+
const duration = 3600n * 24n * 30n;
84+
const expectedStartTime = BigInt(await time.latest()) + 100n;
85+
const expectedEndTime = expectedStartTime + duration;
86+
87+
await crossChainModule.setSubscriptionSynchronizer(ethers.ZeroAddress);
88+
89+
expect(await crossChainModule.getSubscriptionStartTime(FIRST)).to.be.eq(0n);
90+
expect(await crossChainModule.getSubscriptionEndTime(FIRST)).to.be.eq(await time.latest());
91+
expect(await crossChainModule.hasSubscription(FIRST)).to.be.false;
92+
expect(await crossChainModule.hasActiveSubscription(FIRST)).to.be.false;
93+
expect(await crossChainModule.hasSubscriptionDebt(FIRST)).to.be.false;
94+
95+
await time.setNextBlockTimestamp(expectedStartTime);
96+
const tx = await crossChainModule.extendSubscription(FIRST, duration);
97+
98+
await expect(tx)
99+
.to.emit(crossChainModule, "SubscriptionExtended")
100+
.withArgs(FIRST.address, duration, expectedEndTime);
101+
102+
expect(await crossChainModule.getSubscriptionStartTime(FIRST)).to.be.eq(expectedStartTime);
103+
expect(await crossChainModule.getSubscriptionEndTime(FIRST)).to.be.eq(expectedEndTime);
104+
expect(await crossChainModule.hasSubscription(FIRST)).to.be.true;
105+
expect(await crossChainModule.hasActiveSubscription(FIRST)).to.be.true;
106+
expect(await crossChainModule.hasSubscriptionDebt(FIRST)).to.be.false;
107+
});
99108
});
100109
});

0 commit comments

Comments
 (0)