@@ -3,28 +3,44 @@ import {
3
3
fallbackResponder ,
4
4
validateRequest ,
5
5
} from "../../src/evm" ;
6
- import { zeroAddress } from "viem" ;
6
+ import { getAddress , zeroAddress } from "viem" ;
7
7
import { NextRequest , NextResponse } from "next/server" ;
8
8
import type { BaseRequest } from "../../src/evm" ;
9
+ import { hexifyValue } from "../../src/evm" ;
9
10
10
- // Mock external dependencies
11
- jest . mock ( "viem" , ( ) => ( {
12
- getAddress : jest . fn ( ) . mockImplementation ( ( address ) => address ) ,
13
- zeroAddress : "0x0000000000000000000000000000000000000000" ,
14
- } ) ) ;
11
+ const address = ( i : number ) : `0x${ string } ` =>
12
+ getAddress ( `0x ${ i . toString ( 16 ) . padStart ( 40 , "0" ) } ` ) ;
13
+
14
+ const to = address ( 123 ) ;
15
+ const from = address ( 456 ) ;
15
16
16
17
jest . mock ( "near-safe" , ( ) => ( {
17
18
NearSafe : {
18
19
create : jest . fn ( ) . mockImplementation ( async ( ) => ( {
19
- address : "0x123" ,
20
+ address : to ,
20
21
} ) ) ,
21
22
} ,
22
23
} ) ) ;
23
24
24
25
describe ( "evm/index" , ( ) => {
26
+ describe ( "hexifyValue" , ( ) => {
27
+ it ( "does the thing" , ( ) => {
28
+ expect ( hexifyValue ( "0x00" ) ) . toEqual ( "0x00" ) ;
29
+
30
+ expect ( hexifyValue ( "0" ) ) . toEqual ( "0x00" ) ;
31
+ expect ( hexifyValue ( "1" ) ) . toEqual ( "0x01" ) ;
32
+ expect ( hexifyValue ( "15" ) ) . toEqual ( "0x0f" ) ;
33
+ expect ( hexifyValue ( "16" ) ) . toEqual ( "0x10" ) ;
34
+ expect ( hexifyValue ( "17" ) ) . toEqual ( "0x11" ) ;
35
+ expect ( hexifyValue ( "255" ) ) . toEqual ( "0xff" ) ;
36
+ expect ( hexifyValue ( "256" ) ) . toEqual ( "0x0100" ) ;
37
+ expect ( hexifyValue ( "257" ) ) . toEqual ( "0x0101" ) ;
38
+ expect ( hexifyValue ( "256" ) ) . toEqual ( "0x0100" ) ;
39
+ } ) ;
40
+ } ) ;
25
41
describe ( "signRequestFor" , ( ) => {
26
42
it ( "creates a sign request with default from address" , ( ) => {
27
- const metaTransactions = [ { to : "0x123" , value : "0x0 " , data : "0xabc" } ] ;
43
+ const metaTransactions = [ { to, value : "0x00 " , data : "0xabc" } ] ;
28
44
29
45
const result = signRequestFor ( {
30
46
chainId : 1 ,
@@ -37,19 +53,19 @@ describe("evm/index", () => {
37
53
params : [
38
54
{
39
55
from : zeroAddress ,
40
- to : "0x123" ,
41
- value : "0x0 " ,
56
+ to,
57
+ value : "0x00 " ,
42
58
data : "0xabc" ,
43
59
} ,
44
60
] ,
45
61
} ) ;
46
62
} ) ;
47
63
48
64
it ( "creates a sign request with specified from address" , ( ) => {
49
- const metaTransactions = [ { to : "0x123" , value : "0x0" , data : "0xabc" } ] ;
65
+ const metaTransactions = [ { to, value : "0x0" , data : "0xabc" } ] ;
50
66
51
67
const result = signRequestFor ( {
52
- from : "0x456" ,
68
+ from,
53
69
chainId : 1 ,
54
70
metaTransactions,
55
71
} ) ;
@@ -59,8 +75,8 @@ describe("evm/index", () => {
59
75
chainId : 1 ,
60
76
params : [
61
77
{
62
- from : "0x456" ,
63
- to : "0x123" ,
78
+ from,
79
+ to,
64
80
value : "0x0" ,
65
81
data : "0xabc" ,
66
82
} ,
@@ -132,7 +148,7 @@ describe("evm/index", () => {
132
148
headers : {
133
149
get : jest . fn ( ) . mockReturnValue (
134
150
JSON . stringify ( {
135
- evmAddress : "0x123" ,
151
+ evmAddress : address ( 123 ) ,
136
152
} ) ,
137
153
) ,
138
154
} ,
0 commit comments