Skip to content

Commit 68b4178

Browse files
committed
refactor the tests to work specific faucet
1 parent ce7a321 commit 68b4178

File tree

2 files changed

+49
-73
lines changed

2 files changed

+49
-73
lines changed

e2e/test_claim_token_api.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,26 @@ export const options = {
1616
vus: 1,
1717
iterations: 1,
1818
thresholds: {
19+
'checks': ['rate>=1.0'], // 100% of checks MUST pass
20+
'http_req_failed': ['rate<=0.0'], // 0% HTTP failures allowed
1921
'http_req_duration': ['p(95)<5000'],
2022
},
2123
};
2224

23-
function validateTransactionHash(txHash, expectedFormat) {
24-
if (expectedFormat === 'ethereum') {
25-
return txHash.startsWith('0x') && txHash.length === 66;
26-
} else if (expectedFormat === 'filecoin') {
27-
return txHash.length >= 46 && txHash.length <= 70;
25+
function validateTransactionHash(txHash) {
26+
// Remove outer quotes if present
27+
if (txHash.startsWith('"') && txHash.endsWith('"')) {
28+
txHash = txHash.slice(1, -1);
2829
}
29-
return false;
30+
// Remove inner quotes if present
31+
if (txHash.startsWith('"') && txHash.endsWith('"')) {
32+
txHash = txHash.slice(1, -1);
33+
}
34+
35+
// Both CalibnetFIL and CalibnetUSDFC now return Ethereum format: 0x + 64 hex chars = 66 total
36+
return txHash.startsWith('0x') && txHash.length === 66;
3037
}
3138

32-
// Helper function to make API request
3339
function makeClaimRequest(faucetInfo, address) {
3440
let url = `${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINT}`;
3541
const params = [];
@@ -84,10 +90,9 @@ function testInputValidation() {
8490
console.log('✅ Input validation tests completed');
8591
}
8692

87-
// Test comprehensive rate limiting scenarios
8893
function testRateLimiting() {
89-
console.log('\n📊 Testing Rate Limiting Scenarios...');
90-
console.log('📝 Testing each address format: SuccessImmediate rate limit');
94+
console.log('\n📊 Testing Faucet-Specific Rate Limiting...');
95+
console.log('📝 Pattern: One success per faucetAll addresses for that faucet get rate limited');
9196

9297
TEST_SCENARIOS.RATE_LIMIT_TEST_COOLDOWN_CASES.forEach(testCase => {
9398
const response = makeClaimRequest(testCase.faucet_info, testCase.address);
@@ -97,14 +102,14 @@ function testRateLimiting() {
97102
r.status === testCase.expectedStatus,
98103
}) || errorRate.add(1);
99104

100-
if (response.status === STATUS_CODES.SUCCESS && testCase.expectedTxFormat) {
105+
if (response.status === STATUS_CODES.SUCCESS) {
101106
check(response, {
102-
[`${testCase.name}: ✅ Valid ${testCase.expectedTxFormat} transaction hash`]: (r) =>
103-
validateTransactionHash(r.body.trim(), testCase.expectedTxFormat),
107+
[`${testCase.name}: ✅ Valid transaction hash`]: (r) =>
108+
validateTransactionHash(r.body.trim()),
104109
}) || errorRate.add(1);
105110
}
106111

107-
// Log unexpected cases for debugging
112+
// Log results for debugging
108113
if (response.status !== testCase.expectedStatus) {
109114
console.log(`❌ ${testCase.name}: Expected ${testCase.expectedStatus}, got ${response.status} - ${response.body}`);
110115
}

e2e/test_claim_token_api_config.js

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// API Test Configuration
22
export const API_CONFIG = {
33
// Base URL - can be overridden by API_URL environment variable
4-
BASE_URL: __ENV.API_URL || 'http://127.0.0.1:8787',
4+
BASE_URL: __ENV.API_URL || 'https://forest-explorer.chainsafe.dev',
55
ENDPOINT: '/api/claim_token',
66

77
// Test timeouts
@@ -10,12 +10,12 @@ export const API_CONFIG = {
1010
};
1111

1212
export const TEST_ADDRESSES = {
13-
F1_FORMAT_ADDRESS: 'f1pxxbe7he3c6vcw5as3gfvq33kprpmlufgtjgfdq',
14-
T1_FORMAT_ADDRESS: 't1pxxbe7he3c6vcw5as3gfvq33kprpmlufgtjgfdq',
15-
T410_ADDRESS: 't410fv2oexfiizeuzm3xtoie3gnxfpfwwglg4q3dgxki',
16-
ETH_FORMAT_ADDRESS: '0xAe9C4b9508c929966ef37209b336E5796D632CDc',
17-
T0_ADDRESS: 't0163355',
18-
ETH_ID_CORRESPONDING: '0xff00000000000000000000000000000000027e1b',
13+
F1_FORMAT_ADDRESS: 'f175c2l7wplwrfuhbxqate3apti4sikzyq3y26uxq',
14+
T1_FORMAT_ADDRESS: 't175c2l7wplwrfuhbxqate3apti4sikzyq3y26uxq',
15+
T410_ADDRESS: 't410fo4ek6rlkukhpgnatfa75wxaz3zwnzj45har6u6a',
16+
ETH_FORMAT_ADDRESS: '0x7708aF456aa28EF33413283FDB5C19de6CdCA79d',
17+
T0_ADDRESS: 't0174726',
18+
ETH_ID_CORRESPONDING: '0xff0000000000000000000000000000000002aa86',
1919

2020
INVALID: [
2121
'invalidaddress',
@@ -66,12 +66,19 @@ export const TEST_SCENARIOS = {
6666
expectedErrorContains: 'missing'
6767
},
6868
{
69-
name: 'Missing address parameter',
69+
name: 'Missing address parameter CalibnetFIL',
7070
faucet_info: FaucetTypes.CalibnetFIL,
7171
address: null,
7272
expectedStatus: STATUS_CODES.INTERNAL_SERVER_ERROR,
7373
expectedErrorContains: 'missing'
7474
},
75+
{
76+
name: 'Missing address parameter CalibnetUSDFC',
77+
faucet_info: FaucetTypes.CalibnetUSDFC,
78+
address: null,
79+
expectedStatus: STATUS_CODES.INTERNAL_SERVER_ERROR,
80+
expectedErrorContains: 'missing'
81+
},
7582
{
7683
name: 'MainnetFIL request (should be blocked)',
7784
faucet_info: FaucetTypes.MainnetFIL,
@@ -97,97 +104,61 @@ export const TEST_SCENARIOS = {
97104
],
98105

99106
RATE_LIMIT_TEST_COOLDOWN_CASES: [
100-
// CalibnetFIL with t1 address: success → rate limited
101-
{
102-
name: 'CalibnetFIL with t1 address',
103-
faucet_info: FaucetTypes.CalibnetFIL,
104-
address: TEST_ADDRESSES.T1_FORMAT_ADDRESS,
105-
expectedTxFormat: 'filecoin',
106-
expectedStatus: STATUS_CODES.SUCCESS
107-
},
107+
// === CalibnetFIL Tests: One success → All addresses rate limited ===
108108
{
109-
name: 'CalibnetFIL with t1 address (immediate retry - rate limited)',
109+
name: 'CalibnetFIL with t1 address - SUCCESS (starts 60s cooldown for CalibnetFIL)',
110110
faucet_info: FaucetTypes.CalibnetFIL,
111111
address: TEST_ADDRESSES.T1_FORMAT_ADDRESS,
112-
expectedTxFormat: 'filecoin',
113-
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
114-
},
115-
116-
// CalibnetFIL with t410 and ETH address: success → rate limited
117-
{
118-
name: 'CalibnetFIL with t410 address',
119-
faucet_info: FaucetTypes.CalibnetFIL,
120-
address: TEST_ADDRESSES.T410_ADDRESS,
121-
expectedTxFormat: 'filecoin',
122112
expectedStatus: STATUS_CODES.SUCCESS
123113
},
124114
{
125-
name: 'CalibnetFIL with t410 address (immediate retry - rate limited)',
115+
name: 'CalibnetFIL with t410 address - RATE LIMITED (within CalibnetFIL cooldown)',
126116
faucet_info: FaucetTypes.CalibnetFIL,
127117
address: TEST_ADDRESSES.T410_ADDRESS,
128-
expectedTxFormat: 'filecoin',
129118
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
130119
},
131120
{
132-
name: 'CalibnetFIL with ETH address (immediate retry after t410 - rate limited as ETH and t410 are both same address)',
121+
name: 'CalibnetFIL with ETH address - RATE LIMITED (within CalibnetFIL cooldown)',
133122
faucet_info: FaucetTypes.CalibnetFIL,
134123
address: TEST_ADDRESSES.ETH_FORMAT_ADDRESS,
135-
expectedTxFormat: 'filecoin',
136124
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
137125
},
138-
139-
// CalibnetFIL with t0 address: success → rate limited
140126
{
141-
name: 'CalibnetFIL with t0 address',
127+
name: 'CalibnetFIL with t0 address - RATE LIMITED (within CalibnetFIL cooldown)',
142128
faucet_info: FaucetTypes.CalibnetFIL,
143129
address: TEST_ADDRESSES.T0_ADDRESS,
144-
expectedTxFormat: 'filecoin',
145-
expectedStatus: STATUS_CODES.SUCCESS
130+
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
146131
},
147132
{
148-
name: 'CalibnetFIL with t0 address (immediate retry - rate limited)',
133+
name: 'CalibnetFIL with eth ID address - RATE LIMITED (within CalibnetFIL cooldown)',
149134
faucet_info: FaucetTypes.CalibnetFIL,
150-
address: TEST_ADDRESSES.T0_ADDRESS,
151-
expectedTxFormat: 'filecoin',
135+
address: TEST_ADDRESSES.ETH_ID_CORRESPONDING,
152136
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
153137
},
154138

155-
// CalibnetUSDFC with eth address: success → rate limited
139+
// === CalibnetUSDFC Tests: Independent cooldown from CalibnetFIL ===
156140
{
157-
name: 'CalibnetUSDFC with eth address',
141+
name: 'CalibnetUSDFC with eth address - SUCCESS (starts 60s cooldown for CalibnetUSDFC)',
158142
faucet_info: FaucetTypes.CalibnetUSDFC,
159143
address: TEST_ADDRESSES.ETH_FORMAT_ADDRESS,
160-
expectedTxFormat: 'ethereum',
161144
expectedStatus: STATUS_CODES.SUCCESS
162145
},
163146
{
164-
name: 'CalibnetUSDFC with eth address (immediate retry - rate limited)',
165-
faucet_info: FaucetTypes.CalibnetUSDFC,
166-
address: TEST_ADDRESSES.ETH_FORMAT_ADDRESS,
167-
expectedTxFormat: 'ethereum',
168-
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
169-
},
170-
{
171-
name: 'CalibnetUSDFC with t410 address (immediate retry after ETH - rate limited as ETH and t410 are both same address)',
147+
name: 'CalibnetUSDFC with t410 address - RATE LIMITED (within CalibnetUSDFC cooldown)',
172148
faucet_info: FaucetTypes.CalibnetUSDFC,
173149
address: TEST_ADDRESSES.T410_ADDRESS,
174-
expectedTxFormat: 'ethereum',
175150
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
176151
},
177-
178-
// CalibnetUSDFC with eth ID address: success → rate limited
179152
{
180-
name: 'CalibnetUSDFC with eth ID address',
153+
name: 'CalibnetUSDFC with t0 address - RATE LIMITED (within CalibnetUSDFC cooldown)',
181154
faucet_info: FaucetTypes.CalibnetUSDFC,
182-
address: TEST_ADDRESSES.ETH_ID_CORRESPONDING,
183-
expectedTxFormat: 'ethereum',
184-
expectedStatus: STATUS_CODES.SUCCESS
155+
address: TEST_ADDRESSES.T0_ADDRESS,
156+
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
185157
},
186158
{
187-
name: 'CalibnetUSDFC with eth ID address (immediate retry - rate limited)',
159+
name: 'CalibnetUSDFC with eth ID address - RATE LIMITED (within CalibnetUSDFC cooldown)',
188160
faucet_info: FaucetTypes.CalibnetUSDFC,
189161
address: TEST_ADDRESSES.ETH_ID_CORRESPONDING,
190-
expectedTxFormat: 'ethereum',
191162
expectedStatus: STATUS_CODES.TOO_MANY_REQUESTS
192163
}
193164
]

0 commit comments

Comments
 (0)