Skip to content

Commit

Permalink
fix: update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-ThinhVu committed May 7, 2024
1 parent 5a06962 commit f56ca32
Show file tree
Hide file tree
Showing 2 changed files with 237 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
import org.cardanofoundation.explorer.api.model.request.script.smartcontract.SmartContractFilterRequest;
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptFilterResponse;
import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractDetailResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractFilterResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractTxResponse;
import org.cardanofoundation.explorer.api.model.response.search.ScriptSearchResponse;
import org.cardanofoundation.explorer.api.model.response.token.TokenAddressResponse;
import org.cardanofoundation.explorer.api.model.response.token.TokenFilterResponse;
import org.cardanofoundation.explorer.api.service.ScriptService;
import org.cardanofoundation.explorer.common.entity.enumeration.ScriptType;
Expand Down Expand Up @@ -119,28 +122,28 @@ void testNativeScripts_thenReturn() throws Exception {
.andExpect(jsonPath("$.data[0].scriptHash").value("hash"));
}

// @Test
// void testGetNativeScriptDetail() throws Exception {
// String scriptHash = "a5bb0e5bb275a573d744a021f9b3bff73595468e002755b447e01559";
// NativeScriptResponse response =
// NativeScriptResponse.builder()
// .script("script")
// .numberOfTokens(1L)
// .scriptHash(scriptHash)
// .build();
//
// when(scriptService.getNativeScriptDetail(scriptHash)).thenReturn(response);
//
// mockMvc
// .perform(get("/api/v1/scripts/native-scripts/{scriptHash}", scriptHash))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$").exists())
// .andExpect(jsonPath("$.script").value("script"))
// .andExpect(jsonPath("$.numberOfTokens").value("1"))
// .andExpect(jsonPath("$.scriptHash").value(scriptHash));
//
// verify(scriptService).getNativeScriptDetail(scriptHash);
// }
@Test
void testGetNativeScriptDetail() throws Exception {
String scriptHash = "a5bb0e5bb275a573d744a021f9b3bff73595468e002755b447e01559";
NativeScriptResponse response =
NativeScriptResponse.builder()
.script("script")
.numberOfTokens(1L)
.scriptHash(scriptHash)
.build();

when(scriptService.getNativeScriptDetail(scriptHash)).thenReturn(response);

mockMvc
.perform(get("/api/v1/scripts/native-scripts/{scriptHash}", scriptHash))
.andExpect(status().isOk())
.andExpect(jsonPath("$").exists())
.andExpect(jsonPath("$.script").value("script"))
.andExpect(jsonPath("$.numberOfTokens").value("1"))
.andExpect(jsonPath("$.scriptHash").value(scriptHash));

verify(scriptService).getNativeScriptDetail(scriptHash);
}

@Test
void testVerifyContract() throws Exception {
Expand Down Expand Up @@ -182,30 +185,30 @@ void testGetToken() throws Exception {
.getNativeScriptTokens(scriptHash, PageRequest.of(0, 1, Sort.by("txCount").descending()));
}

// @Test
// void testGetHolder() throws Exception {
// String scriptHash = "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e";
// TokenAddressResponse response =
// TokenAddressResponse.builder()
// .address("addreses")
// .name("name")
// .fingerprint("fingerprint")
// .build();
//
// when(scriptService.getNativeScriptHolders(scriptHash, PageRequest.of(0, 1)))
// .thenReturn(new BaseFilterResponse<>(List.of(response), 1));
//
// mockMvc
// .perform(
// get("/api/v1/scripts/native-scripts/{scriptHash}/holders", scriptHash)
// .param("page", "0")
// .param("size", "1"))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$.data[0].name").value("name"))
// .andExpect(jsonPath("$.data[0].fingerprint").value("fingerprint"));
//
// verify(scriptService).getNativeScriptHolders(scriptHash, PageRequest.of(0, 1));
// }
@Test
void testGetHolder() throws Exception {
String scriptHash = "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e";
TokenAddressResponse response =
TokenAddressResponse.builder()
.address("addreses")
.name("name")
.fingerprint("fingerprint")
.build();

when(scriptService.getNativeScriptHolders(scriptHash, PageRequest.of(0, 1)))
.thenReturn(new BaseFilterResponse<>(List.of(response), 1));

mockMvc
.perform(
get("/api/v1/scripts/native-scripts/{scriptHash}/holders", scriptHash)
.param("page", "0")
.param("size", "1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data[0].name").value("name"))
.andExpect(jsonPath("$.data[0].fingerprint").value("fingerprint"));

verify(scriptService).getNativeScriptHolders(scriptHash, PageRequest.of(0, 1));
}

@Test
void testGetSmartContracts() throws Exception {
Expand All @@ -229,25 +232,25 @@ void testGetSmartContracts() throws Exception {
.getSmartContracts(any(SmartContractFilterRequest.class), any(Pageable.class));
}

// @Test
// void testGetSmartContractsDetails() throws Exception {
// String scriptHash = "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e";
// SmartContractDetailResponse response =
// SmartContractDetailResponse.builder()
// .scriptHash(scriptHash)
// .scriptType(ScriptType.TIMELOCK)
// .build();
//
// when(scriptService.getSmartContractDetail(scriptHash)).thenReturn(response);
//
// mockMvc
// .perform(get("/api/v1/scripts/contracts/{scriptHash}", scriptHash))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$.scriptHash").value(scriptHash))
// .andExpect(jsonPath("$.scriptType").value(String.valueOf(ScriptType.TIMELOCK)));
//
// verify(scriptService).getSmartContractDetail(scriptHash);
// }
@Test
void testGetSmartContractsDetails() throws Exception {
String scriptHash = "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e";
SmartContractDetailResponse response =
SmartContractDetailResponse.builder()
.scriptHash(scriptHash)
.scriptType(ScriptType.TIMELOCK)
.build();

when(scriptService.getSmartContractDetail(scriptHash)).thenReturn(response);

mockMvc
.perform(get("/api/v1/scripts/contracts/{scriptHash}", scriptHash))
.andExpect(status().isOk())
.andExpect(jsonPath("$.scriptHash").value(scriptHash))
.andExpect(jsonPath("$.scriptType").value(String.valueOf(ScriptType.TIMELOCK)));

verify(scriptService).getSmartContractDetail(scriptHash);
}

@Test
void testGetSmartContractsTxs() throws Exception {
Expand Down

0 comments on commit f56ca32

Please sign in to comment.