Skip to content

Commit 2331c9f

Browse files
committed
fix tests for riskid refactoring (#824)
1 parent 1fbc2c6 commit 2331c9f

30 files changed

+90
-104
lines changed

contracts/examples/flight/FlightProduct.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ contract FlightProduct is
522522
if (!exists) {
523523
riskId = _createRisk(abi.encode(flightRisk));
524524
_risks[riskKey] = riskId;
525+
} else {
526+
riskId = _risks[riskKey];
525527
}
526528

527529
FlightLib.checkClusterRisk(

contracts/instance/ProductStore.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ contract ProductStore is
114114

115115
//--- Risk --------------------------------------------------------------//
116116
function createRisk(IRisk.RiskInfo memory info) external restricted() returns (RiskId riskId) {
117-
riskId = _createNextRiskId(info.productNftId);
117+
riskId = _createNextRiskId();
118118
Key32 key = riskId.toKey32();
119119
_createMetadata(key);
120120
_risks[key] = info;

contracts/instance/base/ObjectCounter.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import {RiskId, RiskIdLib} from "../../type/RiskId.sol";
77

88
contract ObjectCounter {
99

10-
mapping(NftId productNftId => uint64 risks) private _riskCounter;
10+
uint64 private _riskCounter = 0;
1111
uint256 private _requestCounter = 0;
1212

1313
function _createNextRequestId() internal returns (RequestId requestId) {
1414
_requestCounter++;
1515
requestId = RequestIdLib.toRequestId(_requestCounter);
1616
}
1717

18-
function _createNextRiskId(NftId productNftId) internal returns (RiskId riskId) {
19-
_riskCounter[productNftId]++;
20-
riskId = RiskIdLib.toRiskId(_riskCounter[productNftId]);
18+
function _createNextRiskId() internal returns (RiskId riskId) {
19+
_riskCounter++;
20+
riskId = RiskIdLib.toRiskId(_riskCounter);
2121
}
2222
}

test/TestBundle.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ contract TestBundle is GifTest {
10981098

10991099
function _createRisk(string memory riskIdStr) internal returns (RiskId riskId) {
11001100
vm.startPrank(productOwner);
1101-
riskId = product.createRisk(riskIdStr, "");
1101+
riskId = product.createRisk("");
11021102
vm.stopPrank();
11031103
}
11041104

test/TestFees.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ contract TestFees is GifTest {
701701
FeeLib.zero());
702702

703703
bytes memory data = "bla di blubb";
704-
RiskId riskId = product.createRisk("42x4711", data);
704+
RiskId riskId = product.createRisk(data);
705705
vm.stopPrank();
706706

707707
if (purchaseWithReferral) {

test/component/distribution/Referral.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ contract ReferralTest is ReferralTestBase {
8989
// create risk
9090
vm.startPrank(productOwner);
9191
bytes memory data = "bla di blubb";
92-
RiskId riskId = product.createRisk("42x4711", data);
92+
RiskId riskId = product.createRisk(data);
9393
vm.stopPrank();
9494

9595
vm.startPrank(customer);
@@ -187,7 +187,7 @@ contract ReferralTest is ReferralTestBase {
187187

188188
vm.startPrank(productOwner);
189189
bytes memory data = "bla di blubb";
190-
RiskId riskId = product.createRisk("42x4711", data);
190+
RiskId riskId = product.createRisk(data);
191191
vm.stopPrank();
192192

193193
vm.startPrank(customer);

test/component/product/PolicyServiceLib.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ contract PolicyServiceLibTest is GifTest {
3333

3434
// create test specific risk
3535
bytes memory data = "bla di blubb";
36-
RiskId riskId = product.createRisk("42x4711", data);
36+
RiskId riskId = product.createRisk(data);
3737

3838
// crete application
3939
uint256 sumInsuredAmount = 1000;
@@ -97,7 +97,7 @@ contract PolicyServiceLibTest is GifTest {
9797

9898
// create test specific risk
9999
bytes memory data = "bla di blubb";
100-
RiskId riskId = product.createRisk("42x4711", data);
100+
RiskId riskId = product.createRisk(data);
101101

102102
// crete application
103103
uint256 sumInsuredAmount = 1000;
@@ -150,7 +150,7 @@ contract PolicyServiceLibTest is GifTest {
150150

151151
// create test specific risk
152152
bytes memory data = "bla di blubb";
153-
RiskId riskId = product.createRisk("42x4711", data);
153+
RiskId riskId = product.createRisk(data);
154154

155155
// crete application
156156
uint256 sumInsuredAmount = 1000;

test/component/product/ProductApplication.t.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ contract ProductApplicationTest is GifTest {
5050

5151
bytes memory data = "bla di blubb";
5252
SimpleProduct dproduct = SimpleProduct(address(product));
53-
RiskId riskId = dproduct.createRisk("42x4711", data);
53+
RiskId riskId = dproduct.createRisk(data);
5454

5555
NftId policyNftId = dproduct.createApplication(
5656
customer,
@@ -77,8 +77,8 @@ contract ProductApplicationTest is GifTest {
7777
function test_Product_createApplication_invalidRisk() public {
7878
vm.startPrank(productOwner);
7979

80-
RiskId riskId = product.createRisk("42x4711", "bla di blubb");
81-
RiskId riskId2 = RiskIdLib.toRiskId(productNftId, "42x4712");
80+
RiskId riskId = product.createRisk("bla di blubb");
81+
RiskId riskId2 = RiskIdLib.toRiskId(888);
8282
Seconds lifetime = SecondsLib.toSeconds(30);
8383
ReferralId noReferral = ReferralLib.zero();
8484
Amount sumInsured = AmountLib.toAmount(1000);
@@ -103,7 +103,7 @@ contract ProductApplicationTest is GifTest {
103103
function test_Product_createApplication_lockedRisk() public {
104104
vm.startPrank(productOwner);
105105

106-
RiskId riskId = product.createRisk("42x4711", "bla di blubb");
106+
RiskId riskId = product.createRisk("bla di blubb");
107107
Seconds lifetime = SecondsLib.toSeconds(30);
108108
ReferralId noReferral = ReferralLib.zero();
109109
Amount sumInsured = AmountLib.toAmount(1000);
@@ -131,7 +131,7 @@ contract ProductApplicationTest is GifTest {
131131
// GIVEN
132132
vm.startPrank(productOwner);
133133

134-
RiskId riskId = product.createRisk("42x4711", "bla di blubb");
134+
RiskId riskId = product.createRisk("bla di blubb");
135135
Seconds lifetime = SecondsLib.toSeconds(30);
136136
ReferralId noReferral = ReferralLib.zero();
137137
Amount sumInsured = AmountLib.toAmount(1000);
@@ -168,7 +168,7 @@ contract ProductApplicationTest is GifTest {
168168
// GIVEN
169169
vm.startPrank(productOwner);
170170

171-
RiskId riskId = product.createRisk("42x4711", "bla di blubb");
171+
RiskId riskId = product.createRisk("bla di blubb");
172172
Seconds lifetime = SecondsLib.toSeconds(30);
173173
ReferralId referralId = ReferralLib.toReferralId(distributionNftId, "UNKNOWN");
174174
Amount sumInsured = AmountLib.toAmount(1000);
@@ -201,7 +201,7 @@ contract ProductApplicationTest is GifTest {
201201

202202
vm.startPrank(productOwner);
203203
bytes memory data = "bla di blubb";
204-
RiskId riskId = product.createRisk("42x4711", data);
204+
RiskId riskId = product.createRisk(data);
205205
vm.stopPrank();
206206

207207
vm.startPrank(customer);
@@ -241,7 +241,7 @@ contract ProductApplicationTest is GifTest {
241241

242242
vm.startPrank(productOwner);
243243
bytes memory data = "bla di blubb";
244-
RiskId riskId = product.createRisk("42x4711", data);
244+
RiskId riskId = product.createRisk(data);
245245
vm.stopPrank();
246246

247247
vm.startPrank(customer);

test/component/product/ProductClaim.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract TestProductClaim is GifTest {
3737

3838
// create risk
3939
vm.startPrank(productOwner);
40-
riskId = product.createRisk("Risk_1", "");
40+
riskId = product.createRisk("");
4141
vm.stopPrank();
4242

4343
// create application

test/component/product/ProductClusterRisk.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ contract ProductClusterRiskTest is GifClusterTest {
2727
string memory riskName = "Risk1";
2828

2929
// WHEN
30-
riskId1 = myProduct1.createRisk(riskName, abi.encode(1,2,3));
31-
riskId2 = myProduct2.createRisk(riskName, abi.encode(1,2,3));
30+
riskId1 = myProduct1.createRisk(abi.encode(1,2,3));
31+
riskId2 = myProduct2.createRisk(abi.encode(1,2,3));
3232

3333
// THEN
3434
assertFalse(riskId1.eq(riskId2), "riskId1 and riskid2 should not be equal");

0 commit comments

Comments
 (0)