Skip to content

Commit

Permalink
Fix blockscout licensetype
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed Nov 19, 2024
1 parent f112a58 commit 1afafda
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
48 changes: 47 additions & 1 deletion src/verifiers/BlockscoutVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,49 @@ export type BlockscoutVerificationRequest = {
waitForSuccess?: boolean
}

// https://docs.blockscout.com/devs/verification/blockscout-smart-contract-verification-api#license-type
type BlockscoutLicenseType =
| 'none'
| 'unlicense'
| 'mit'
| 'gnu_gpl_v2'
| 'gnu_gpl_v3'
| 'gnu_lgpl_v2_1'
| 'gnu_lgpl_v3'
| 'bsd_2_clause'
| 'bsd_3_clause'
| 'mpl_2_0'
| 'osl_3_0'
| 'apache_2_0'
| 'gnu_agpl_v3'
| 'bsl_1_1'

const BLOCKSCOUT_LICENSE_TYPE_MAP: Record<string, BlockscoutLicenseType> = {
None: 'none',
Unlicense: 'unlicense',
MIT: 'mit',
'GNU GPLv2': 'gnu_gpl_v2',
'GNU GPLv3': 'gnu_gpl_v3',
'GNU LGPLv2.1': 'gnu_lgpl_v2_1',
'GNU LGPLv3': 'gnu_lgpl_v3',
'BSD-2-Clause': 'bsd_2_clause',
'BSD-3-Clause': 'bsd_3_clause',
'MPL-2.0': 'mpl_2_0',
'OSL-3.0': 'osl_3_0',
'Apache-2.0': 'apache_2_0',
'GNU AGPLv3': 'gnu_agpl_v3',
'BSL 1.1': 'bsl_1_1',
}

const stringToBlockscoutLicenseType = (
licenseString: string,
): BlockscoutLicenseType | string => {
if (!(licenseString in BLOCKSCOUT_LICENSE_TYPE_MAP)) {
return licenseString // Just return the original string
}
return BLOCKSCOUT_LICENSE_TYPE_MAP[licenseString]
}

type BlockscoutApiResponse = {
message: string
}
Expand All @@ -36,7 +79,10 @@ export class BlockscoutVerifier {
// Create verification body
const verifyBody = new FormData()
verifyBody.append('compiler_version', request.version)
verifyBody.append('license_type', request.licenceType.toLowerCase())
verifyBody.append(
'license_type',
stringToBlockscoutLicenseType(request.licenceType),
)
verifyBody.append('contract_name', contractName)
verifyBody.append('autodetect_constructor_args', 'false')
verifyBody.append('constructor_args', request.constructorArgs ?? '')
Expand Down
8 changes: 4 additions & 4 deletions tests/verifiers/BlockscoutVerify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ describe('BlockscoutVerifier', () => {
let contractAddr = COUNTER_ADDR_SEPOLIA

beforeAll(async () => {
const { SEPOLIA_PRIVATE_KEY, SEPOLIA_RPC_URL } = process.env
if (SEPOLIA_PRIVATE_KEY === undefined || SEPOLIA_RPC_URL === undefined) {
const { SEPOLIA_PRIVATE_KEY, SEPOLIA_RPC_URL, BLOCKSCOUT_URL } = process.env
if (!SEPOLIA_PRIVATE_KEY || !SEPOLIA_RPC_URL) {
// Stub fetch
console.log('Required Sepolia env vars not found, using stubs')
axiosPostStub = jest.spyOn(axios, 'postForm')
axiosPostStub
.mockResolvedValueOnce({
.mockResolvedValueOnce({
data: { message: 'Smart-contract verification started' },
})
.mockResolvedValueOnce({
Expand All @@ -42,7 +42,7 @@ describe('BlockscoutVerifier', () => {
}

blockscoutVerifier = new BlockscoutVerifier(
'https://eth-sepolia.blockscout.com',
BLOCKSCOUT_URL ?? 'https://eth-sepolia.blockscout.com',
console,
)
})
Expand Down

0 comments on commit 1afafda

Please sign in to comment.