Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit trailing / in remappings causes file remappings to not resolve #7527

Closed
2 tasks done
BlazeWasHere opened this issue Mar 30, 2024 · 8 comments
Closed
2 tasks done
Assignees
Labels
A-dependencies Area: dependencies C-forge Command: forge T-bug Type: bug

Comments

@BlazeWasHere
Copy link

BlazeWasHere commented Mar 30, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (d1ab09d 2024-03-30T00:17:25.901579435Z)

What command(s) is the bug in?

No response

Operating System

Linux

Describe the bug

Using remappings.txt

ds-test/=lib/ds-test/src/
src/test.sol=src/testPatched.sol

when ran with forge (notice how its src/test.sol/ instead of src/test.sol)

~> forge remappings 
ds-test/=lib/ds-test/src/
src/test.sol/=src/testPatched.sol/

expected behavior is similar to dapptools -- no trailing / is added to the remapping.

simple testcase:

A.t.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.6;

import "ds-test/test.sol";

import {Test} from "src/test.sol";

contract ATest is DSTest {
    function test_basic_sanity() public {
        Test.log();
        assertTrue(true);
    }
}
test.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.6;

library Test {
    event log_string(string);

    function log() internal {
        emit log_string("test");
    }
}
testPatched.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.6;

library Test {
    event log_string(string);

    function log() internal {
        emit log_string("patched");
    }
}

now we run forge:

~> forge test -vv
[⠊] Compiling...
No files changed, compilation skipped

Ran 1 test for src/A.t.sol:ATest
[PASS] test_basic_sanity() (gas: 1821)
Logs:
  test

with dapptools:

~> DAPP_REMAPPINGS=$(cat remappings.txt) dapp test --verbosity 2 
 dapp-build: building with linked libraries
dapp: Predeploying test library src/testPatched.sol:Test at 0x0DdeDfFe2789df61F5f76479464F568334414389
dapp: Predeploying test library src/test.sol:Test at 0x5Fe5dAc04fe3527Cf7bDba8798F5A8b5edDfE4Af
Running 1 tests for src/A.t.sol:ATest
[PASS] test_basic_sanity() (gas: 1994)

Success: test_basic_sanity
  
  "patched"

it does seem like this will be a breaking change if implemented due to some people who may be relying on this unexpected behavior, wdyt?

@BlazeWasHere BlazeWasHere added the T-bug Type: bug label Mar 30, 2024
@BlazeWasHere
Copy link
Author

BlazeWasHere commented Mar 30, 2024

seems like its caused by this

let mut r = Remapping {
context: None,
name: format!("{dir_name}/"),
path: format!("{}", dir.display()),
};
if !r.path.ends_with('/') {
r.path.push('/')
}
Some(r)

if let Some(name) = lib.file_name().and_then(|s| s.to_str()) {
let mut r = Remapping {
context: None,
name: format!("{name}/"),
path: format!("{}", lib.join(&config.src).display()),
};
if !r.path.ends_with('/') {
r.path.push('/')
}
src_remapping = Some(r);
}

this looks related https://github.com/foundry-rs/compilers/issues/47

@zerosnacks
Copy link
Member

zerosnacks commented Jul 12, 2024

This seems related to #6706

you cannot remap individual files, only directories

@zerosnacks zerosnacks added C-forge Command: forge A-dependencies Area: dependencies labels Jul 12, 2024
@BlazeWasHere
Copy link
Author

@zerosnacks i believe this issue was fixed in foundry-rs/compilers#49 and all tests passed in foundry CI #8377 so im guessing we are waiting for foundry main to update to the latest version of foundry-compilers

@zerosnacks zerosnacks self-assigned this Jul 12, 2024
@zerosnacks
Copy link
Member

zerosnacks commented Jul 12, 2024

Thanks @BlazeWasHere, looks like that should fix it!

I'll follow up on this once a new release of foundry-compilers is cut (should be relatively soon) and we have bumped the version in Foundry

@zerosnacks
Copy link
Member

zerosnacks commented Jul 25, 2024

Marking as resolved as foundry-compilers has been updated: foundry-rs/compilers@ea34637 +

foundry-compilers = { version = "0.10.0", default-features = false }

@BlazeWasHere
Copy link
Author

@zerosnacks doesnt look like original poc has been fixed with latest nightly (00ff367) + (37ea1e9). should i create a test case for this?

$ DAPP_REMAPPINGS=$(cat remappings.txt) dapp test --verbosity 2  
 dapp-build: building with linked libraries
[...]

  src/A.t.sol:ATest
   ├╴constructor
   └╴test_basic_sanity()
      ├╴log_string("patched") (src/testPatched.sol:8)
[...]
  
  "patched" # <--- this is good :)


$ forge test -vvv 
[...]
Logs:
  test # <--- this is bad :(

@zerosnacks
Copy link
Member

Hi @BlazeWasHere, that would be appreciated. However I'm still not sure what the intended behavior here would be because Foundry does not support remapping individual files to my knowledge, only directories.

@BlazeWasHere
Copy link
Author

@zerosnacks Correct that Foundry does not support individual file remappings, ideally it should (foundry-compilers does) but i think that's related to #6706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dependencies Area: dependencies C-forge Command: forge T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants