diff --git a/cadence/transactions/register-contract.cdc b/cadence/transactions/register-contract.cdc index 74fa7cc8..ac639b5d 100644 --- a/cadence/transactions/register-contract.cdc +++ b/cadence/transactions/register-contract.cdc @@ -3,7 +3,7 @@ import FlowManager from 0x01 transaction(name: String, address: Address) { prepare(signer: auth(BorrowValue) &Account){ let linkPath = FlowManager.contractManagerPath - let contractManager = getAccount(manager).capabilities.borrow<&FlowManager.Mapper>(linkPath)! + let contractManager = signer.capabilities.borrow<&FlowManager.Mapper>(linkPath)! contractManager.setAddress(name, address: address) } } diff --git a/src/generated/transactions/registerContract.js b/src/generated/transactions/registerContract.js index d4672faf..726b77ea 100644 --- a/src/generated/transactions/registerContract.js +++ b/src/generated/transactions/registerContract.js @@ -14,7 +14,7 @@ import FlowManager from 0x01 transaction(name: String, address: Address) { prepare(signer: auth(BorrowValue) &Account){ let linkPath = FlowManager.contractManagerPath - let contractManager = getAccount(manager).capabilities.borrow<&FlowManager.Mapper>(linkPath)! + let contractManager = signer.capabilities.borrow<&FlowManager.Mapper>(linkPath)! contractManager.setAddress(name, address: address) } } diff --git a/src/imports.js b/src/imports.js index 568dd1a5..021037b0 100644 --- a/src/imports.js +++ b/src/imports.js @@ -45,7 +45,17 @@ export const resolveImports = async code => { const addressMap = {} const importList = extractImports(fixShorthandImports(code)) for (const key in importList) { - if (defaultsByName[key]) { + if ( + key !== "FlowManager" && + importList[key] && + importList[key].toLowerCase().startsWith("0x") && + importList[key].length === 18 + ) { + addressMap[key] = importList[key] + } else if ( + defaultsByName[key] && + !(importList[key] && importList[key] === '"DYNAMIC"') + ) { addressMap[key] = defaultsByName[key] } else { const address = await getContractAddress(key) diff --git a/src/index.js b/src/index.js index 2eb7257a..18480e77 100644 --- a/src/index.js +++ b/src/index.js @@ -23,6 +23,7 @@ export { getScriptCode, getContractCode, getTransactionCode, + defaultsByName, } from "./file" export {sendTransaction, executeScript} from "./interaction" export {getFlowBalance, mintFlow} from "./flow-token" diff --git a/test/integration/imports.test.js b/test/integration/imports.test.js index 435581b6..0bfe2217 100644 --- a/test/integration/imports.test.js +++ b/test/integration/imports.test.js @@ -5,8 +5,9 @@ import { deployContract, resolveImports, getServiceAddress, + getAccountAddress, } from "../../src" -import {defaultsByName} from "../../src/file" +import {defaultsByName} from "../../src" import {DEFAULT_TEST_TIMEOUT} from "../util/timeout.const" import {fixShorthandImports} from "../../src/imports" @@ -32,11 +33,13 @@ describe("import resolver", () => { }) test("use imports", async () => { + const Dynamic = await getAccountAddress("Dynamic") await deployContract({code: emptyContract("First"), name: "First"}) await deployContract({code: emptyContract("Second"), name: "Second"}) await deployContract({code: emptyContract("Third"), name: "Third"}) await deployContract({code: emptyContract("A"), name: "A"}) await deployContract({code: emptyContract("B"), name: "B"}) + await deployContract({code: emptyContract("Dynamo"), name: "Dynamo", to: Dynamic}) const code = ` import First from 0xFIRST @@ -47,6 +50,10 @@ describe("import resolver", () => { import FungibleToken from 0xFUNGIBLETOKEN import FlowToken from 0xFLOWTOKEN + import Dynamo from "DYNAMIC" + import Direct from 0x0123456789012345 + import FlowFees from 0x0123456789012345 + access(all) fun main(){} ` @@ -64,5 +71,9 @@ describe("import resolver", () => { expect(B).toBe(Registry) expect(FungibleToken).toBe(defaultsByName.FungibleToken) expect(FlowToken).toBe(defaultsByName.FlowToken) + const {Dynamo, Direct, FlowFees} = addressMap + expect(Dynamo).toBe(Dynamic) + expect(Direct).toBe('0x0123456789012345') + expect(FlowFees).toBe('0x0123456789012345') }) })