Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 26, 2024. It is now read-only.
/etherscan-apiPublic archive

Commit4e454c7

Browse files
committed
Implementing first parts of the client constructor
1 parent328262a commit4e454c7

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

‎src/Client.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import{account}from'./actions/account'
2+
import{ApiKey}from'./entities/Apikey'
3+
4+
exportclassClient{
5+
privateapiKey:ApiKey
6+
constructor(apiKey:string){
7+
this.apiKey=newApiKey(apiKey)
8+
this.apiKey.validate()
9+
}
10+
account(action:string):void{
11+
if(!account.get(action)){
12+
thrownewError('unknown action')
13+
}
14+
}
15+
}

‎src/entities/Apikey.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { EntityBase } from './EntityBase'
66
exportclassApiKeyextendsEntityBaseimplementsIEntity{
77
errorMessage:string='invalid'
88
privateapiKey:string
9-
privatekeyLength:number=33
9+
privatekeyLength:number=34
1010
constructor(apiKey:string){
1111
super()
1212
this.apiKey=apiKey
1313
}
1414

1515
valid():boolean{
16-
returnthis.apiKey.length!==this.keyLength
16+
returnthis.apiKey.length===this.keyLength
1717
}
1818
}

‎test/ClientTest.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
importtestfrom'ava'
2+
import{Client}from'../src/Client'
3+
4+
test('constructor is a function',t=>{
5+
t.is(typeofClient,'function')
6+
})
7+
8+
test('client can be instantiated',t=>{
9+
t.notThrows(()=>newClient('TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1W'))
10+
});
11+
12+
test('invalid api key throws',t=>{
13+
t.throws(()=>newClient('y'))
14+
});

‎test/entities/ApikeyTest.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ test('Instantiated', (t)=> {
88
t.truthy(a)
99
})
1010

11-
test('is valid',(t)=>{
11+
test('key TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1Wis valid',(t)=>{
1212
constapiKey='TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1W'
1313
consta=newApiKey(apiKey)
1414
t.truthy(a.valid())
1515
})
1616

17+
test('foo is valid',(t)=>{
18+
constapiKey='foo'
19+
consta=newApiKey(apiKey)
20+
t.false(a.valid())
21+
})
22+
23+
24+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp