Skip to content

codebase 测试

weilong wu edited this page Mar 25, 2026 · 1 revision

测试

返回首页 | GSL 项目归档文档

分析日期:2026-03-25

Summary

Testing across all four sub-projects is minimal to absent. No test files exist in any sub-project. The Java project has <skipTests>true</skipTests> set permanently in pom.xml. The Solidity project has a Foundry test configuration but no test files. The two Vue projects have no test runner configured at all.


gsl-contracts (Solidity / Foundry)

Test Framework

Runner: Foundry (forge test)

  • Config: gsl-contracts/foundry.toml
  • Solidity version: 0.8.25
  • Optimizer: enabled, 200 runs

Fuzz Testing Config:

[profile.default.fuzz]
runs = 10

Fuzz runs set to 10 (very low — default is 256). Indicates fuzz config exists but is not actively maintained.

Run Commands:

forge test              # Run all tests
forge test -vvvv        # Verbose output
forge test --match-test testFunctionName  # Run specific test
forge coverage          # Coverage report

Test File Organization

Location: Tests would live in gsl-contracts/test/ (Foundry convention)

  • No test files currently exist in this directory

Naming Convention (Foundry standard, to follow when adding tests):

  • File: MyContract.t.sol
  • Test contract: MyContractTest
  • Test function: test_functionName or testFuzz_functionName

Expected Test Structure (Foundry)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import {MyContract} from "../src/MyContract.sol";

contract MyContractTest is Test {
    MyContract public myContract;

    function setUp() public {
        myContract = new MyContract();
        myContract.initialize(address(1), address(this));
    }

    function test_initialize() public {
        assertEq(address(myContract.owner()), address(this));
    }

    function testFuzz_stakeAmount(uint256 amount) public {
        vm.assume(amount > 0 && amount < type(uint128).max);
        // test logic
    }
}

Import Path (remappings)

forge-std/=lib/forge-std/src/
@openzeppelin/=lib/openzeppelin-contracts/
@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/

Mocking (Foundry cheatcodes)

// Impersonate an address
vm.prank(userAddress);
myContract.stake(amount);

// Set block timestamp
vm.warp(block.timestamp + 1 days);

// Set ETH balance
vm.deal(userAddress, 1 ether);

// Expect revert
vm.expectRevert("Error message");
myContract.failingFunction();

// Expect event
vm.expectEmit(true, true, false, true);
emit Stake(userAddress, amount);
myContract.stake(amount);

What to Test (Priority list for new tests)

  • APYStatistics.calculateDynamicAPY — complex math with lookup tables
  • AbstractStakeMiningV2Upgradeable stake/claim/withdraw flows — core economic logic
  • FOMO3D.play — game timing and win logic
  • HiveSwap swap paths — multi-token swap routing
  • UUPS upgrade authorization — _authorizeUpgrade must reject non-owner

Coverage

Requirements: None enforced View coverage:

forge coverage --report lcov

hive-gls-java (Java / Spring Boot / JUnit)

Test Framework

Runner: JUnit 4 (declared in pom.xml)

  • spring-boot-starter-test also present (includes JUnit 5 + Mockito)
  • Config: hive-gls-java/pom.xml

Critical Note: Tests are globally skipped:

<skipTests>true</skipTests>

This means mvn package and mvn install never run tests. Tests must be run explicitly with mvn test -DskipTests=false.

Run Commands:

mvn test                          # Skipped by default (skipTests=true)
mvn test -DskipTests=false        # Force run tests
mvn test -Dtest=MyTestClass       # Run specific test class

Test File Organization

Location: hive-gls-java/src/test/java/com/unknown/gsl/

  • No test files currently exist

Naming (Spring Boot convention to follow):

  • File: [ClassName]Test.java
  • Package mirrors main source: com.unknown.gsl.[layer]

Expected Test Structure

@SpringBootTest
@RunWith(SpringRunner.class)
public class OrderServiceTest {

    @Autowired
    private OrderService orderService;

    @MockBean
    private OrderMapper orderMapper;

    @Test
    public void testProcessChainCreateOrder() {
        // Arrange
        AddressProductPay mockPay = new AddressProductPay();
        mockPay.setStatus(ProductPayStatus.CONFIRM_SUCCESS.value);
        // ...

        // Act
        orderService.processChainCreateOrder(mockPay);

        // Assert
        verify(orderMapper, times(1)).insertSelective(any(Order.class));
    }
}

Mocking

Framework: Mockito (included via spring-boot-starter-test)

@MockBean
private CoinPayConfigService coinPayConfigService;

when(coinPayConfigService.lambdaQuery()
    .eq(CoinPayConfig::getCoinSymbol, "HIVE")
    .one())
    .thenReturn(mockConfig);

What to Test (Priority list for new tests)

  • OrderServiceImpl.processChainCreateOrder — blockchain event decoding and order creation
  • OrderServiceImpl.processOrderRelease — transactional state machine update
  • AddressInfoServiceImpl — user hierarchy and investment tracking
  • EventServiceJob.executeInternal — scheduled job isolation and Redis lock behavior
  • Admin controllers — input validation and pagination

Coverage

Requirements: None enforced (skipTests=true prevents any baseline) View coverage:

mvn jacoco:report  # If jacoco plugin is added

gsl-web-admin (Vue 3 + TypeScript / Vite)

Test Framework

Status: No test framework configured

  • No jest.config.*, vitest.config.*, or equivalent file
  • No test dependencies in gsl-web-admin/package.json
  • No test scripts in package.json

Run Commands: None available

Test File Organization

No test files exist anywhere in gsl-web-admin/src/.

Recommended Setup (if adding tests)

Vitest is the natural choice given the Vite build setup:

npm install -D vitest @vue/test-utils happy-dom

Add to package.json:

{
  "scripts": {
    "test": "vitest",
    "test:coverage": "vitest --coverage"
  }
}

Expected file location: co-located or in src/__tests__/

What to Test (Priority list)

  • src/utils/request.ts — HTTP interceptor logic (complex branching for auth flows)
  • src/utils/formatTime.ts, src/utils/toolsValidate.ts — pure utility functions
  • Pinia stores in src/stores/ — state transitions and actions

gsl-dapp (Vue 3 + JavaScript / Vite)

Test Framework

Status: No test framework configured

  • No test dependencies in gsl-dapp/package.json
  • No test scripts in package.json

Run Commands: None available

Test File Organization

No test files exist anywhere in gsl-dapp/src/.

What to Test (Priority list)

  • src/request/request.js — HTTP interceptor and error code handling
  • src/utils/global.js — contract address config and chain switching logic
  • src/stores/index.js — Pinia store actions

Cross-Project Testing Summary

Project Framework Tests Exist CI Enforced
gsl-contracts Foundry No No
hive-gls-java JUnit 4 + Spring Boot Test No No (skipTests=true)
gsl-web-admin None configured No No
gsl-dapp None configured No No

No project has any tests. All test infrastructure additions must be built from scratch. The Java project has the most critical gap given it handles on-chain financial event processing.


Testing analysis: 2026-03-25


返回首页 | GSL 项目归档文档 | 生成日期:2026-03-25

Clone this wiki locally